[Django] #28961: Convert result of the predicate in the function django.utils.functional.partition to bool

5 views
Skip to first unread message

Django

unread,
Dec 25, 2017, 7:08:48 AM12/25/17
to django-...@googlegroups.com
#28961: Convert result of the predicate in the function
django.utils.functional.partition to bool
-------------------------------------+-------------------------------------
Reporter: Vitaliy | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Utilities | Version: 1.11
Severity: Normal | Keywords: functional
Triage Stage: | partition
Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
{{{#!python
def partition(predicate, values):
results = ([], [])
for item in values:
results[bool(predicate(item))].append(item)
return results
}}}

This will make the `partition` function more convenient
{{{#!python
>>> def idf(x): return x
>>> partition(idf, [True, False, '', 1, 2])
([False, ''], [True, 1, 2])
}}}

or make the behaviour of the function more similar to
[https://hackage.haskell.org/package/base-4.10.1.0/docs/Data-
List.html#v:partition `Haskell partition`]

The partition function takes a predicate a list and returns the pair
of lists of elements which do and do not satisfy the predicate,
respectively

{{{#!python
def partition(predicate, values):
results = ([], [])
for item in values:
results[not predicate(item)].append(item)
return results

>>> def idf(x): return x
>>> partition(idf, [True, False, '', 1, 2])
([True, 1, 2], [False, ''])
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28961>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 26, 2017, 4:26:19 AM12/26/17
to django-...@googlegroups.com
#28961: Convert result of predicate in the function

django.utils.functional.partition to bool
-------------------------------------+-------------------------------------
Reporter: Vitaliy | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Utilities | Version: 1.11
Severity: Normal | Resolution:

Keywords: functional | Triage Stage:
partition | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

--
Ticket URL: <https://code.djangoproject.com/ticket/28961#comment:1>

Django

unread,
Dec 26, 2017, 11:24:20 AM12/26/17
to django-...@googlegroups.com
#28961: Convert result of predicate in the function

django.utils.functional.partition to bool
-------------------------------------+-------------------------------------
Reporter: Vitaliy | Owner: nobody
Type: | Status: closed

Cleanup/optimization |
Component: Utilities | Version: 1.11
Severity: Normal | Resolution: wontfix

Keywords: functional | Triage Stage:
partition | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* status: new => closed
* resolution: => wontfix


Comment:

`partition()` isn't a documented function and I don't see a strong reason
to add logic to it that Django's usage doesn't require.

--
Ticket URL: <https://code.djangoproject.com/ticket/28961#comment:2>

Reply all
Reply to author
Forward
0 new messages