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

Nick Coghlan ncoghlan at gmail.com
Sun Aug 24 06:24:53 CEST 2014


On 24 August 2014 01:30, Warren Weckesser <warren.weckesser at gmail.com> wrote:
> I'd like to add an additional optional argument to functools.reduce.
> The argument is the "nullifier" of the reducing operation.  It is a value
> such that function(nullifier, anything) returns nullifier.  For example, if
> function(x, y) computes x*y, the nullifier is 0.  If function(x, y) is
> the intersection of the sets x and y, the nullifier is the empty set.

When it comes to judging the usefulness of functional programming
features these days, my first question is generally going to be "Does
PyToolz offer this?"

Grumblings about the name aside, it's still the solution I recommend
to folks that wish Python had more functional programming tools in the
standard library: http://toolz.readthedocs.org/en/latest/api.html

There's even a Cython accelerated version available (Cytoolz).

"pip install toolz" for the pure Python version, "pip install cytoolz"
for the accelerated one.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-ideas mailing list