a few extensions for the itertools

Kay Schluehr kay.schluehr at gmx.net
Tue Nov 21 03:14:35 EST 2006


Klaas wrote:
> Mathias Panzenboeck wrote:
>
> > It's like the . operator in haskell:
> >
> > fchain(f,g,h) is the same like lambda *args,**kwargs: f(g(h(*args,**kwargs)))
>
> I used this once:
>
> composedfun = lambda arg: reduce(lambda x, f: f(x), funcs, arg)
>
> so I can see the potential need (it is not terribly obvious in short-
> or long- form).
>
> If this belongs anywhere, though, it is functools, not itertools.
>
> -Mike

Since you are going to exploit the universality of fold [1] here. Maybe
we should also take the next step beyond itertools ( i.e.
generatortools ) into account?

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/498264

Of course I've nothing against a nice interface for the most convenient
usecases just like the proposed isum that could be expressed by
greduce. 

[1] http://www.cs.nott.ac.uk/~gmh/fold.pdf




More information about the Python-list mailing list