[Python-ideas] itertools has starmap but no starreduce?

Andrey Fedorov anfedorov at gmail.com
Fri Feb 12 19:59:08 CET 2010


>
> On Fri, Feb 12, 2010 at 11:54 AM, Vitor Bosshard <algorias at gmail.com>
>  wrote:

I assume you mean that the following lines would be equivalent:


> starreduce(f, iterable, initial)

reduce(lambda x,y: f(x, *y), iterable, initial)


Precisely.

It seems like a very narrow use-case [...]


Agreed, that example is. I also use it for high-level functional stuff -
something like Haskell's monads or Java's "chain-of-responsibility". Like:

    output = reduce(lambda x, f: f(x), chain_of_processors, input)

So, given a list [f,g,h], this would be h(g(f(input))). The star-case is
when input is a n-touple, and each function works on `n' arguments. But now
that I wrote it out without a for loop, it's obviously trivial to add the
star in the right place. My mistake! Thanks for helping me catch it :)

Cheers,
Andrey
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20100212/317ac645/attachment.html>


More information about the Python-ideas mailing list