[Python-ideas] Add nullifier argument to functools.reduce?

MRAB python at mrabarnett.plus.com
Sun Aug 24 17:27:35 CEST 2014


On 2014-08-24 15:56, Warren Weckesser wrote:
[snip]
>
> An example I gave earlier  is the reduction of a collection of sets
> using set intersection.  It is possible that (set1 & set2) gives the
> empty set, so the nullifier can occur during the reduction without being
> in the given iterable.  E.g.:
>
>      reduce(lambda x, y: x & y, [{1,2}, {3}, {4, 5}, {6}], nullifier={})
>
> That should stop iterating after the first operation.
>
I think it would be more flexible if, instead of a 'nullifier' object,
there were an 'until' or 'while_' predicate:

reduce(lambda x, y: x & y, [{1,2}, {3}, {4, 5}, {6}], while_=bool)



More information about the Python-ideas mailing list