[Python-ideas] Predicate Sets
David Mertz
mertz at gnosis.cx
Tue Jan 21 19:39:20 CET 2014
Isn't that exactly what I suggested up-thread with my suggested small
library of combinators? E.g.:
def allP(*fns):
return lambda x: all(f(x) for f in fns)
I like encapsulating it better since it encourages naming such combined
functions, e.g.:
this_and_that = allP((this, that))
I feel like that encourages reuse and readability when one later wants to
write:
set_with_predicate = {x for x in baseset if this_and_that(x)}
Or:
if this_and_that(x): ...
On Tue, Jan 21, 2014 at 1:09 AM, Serhiy Storchaka <storchaka at gmail.com>wrote:
> 21.01.14 10:58, Haoyi Li написав(ла):
>
>> > *all(map(list_of_filters, value))*
>>
>>
>> Scratch that, what I actually want is
>>
>> *all(map(lambda f: f(value), list_of_filters))*
>> *
>> *
>> I always mix up the order of things going into *map* =(*
>> *
>>
>
> all(f(value) for f in list_of_filters)
>
> looks cleaner to me.
>
> Perhaps slightly more efficient (but much less readable) form:
>
> all(map(operator.methodcaller('__call__', value), list_of_filters)
>
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
--
Keeping medicines from the bloodstreams of the sick; food
from the bellies of the hungry; books from the hands of the
uneducated; technology from the underdeveloped; and putting
advocates of freedom in prisons. Intellectual property is
to the 21st century what the slave trade was to the 16th.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140121/21d21647/attachment.html>
More information about the Python-ideas
mailing list