[Python-Dev] functools additions

BJörn Lindqvist bjourne at gmail.com
Mon Apr 16 00:36:42 CEST 2007


> def cat(x): return x
>
> def multimap(func, s, n=2):
>     assert n > 0, "n must be positive"
>     return (map(func, seq)
>             if n == 1 else
>             map(lambda x: multimap(func, x, n-1),
>                 seq))
>
> def multifilter(func, s, n=2):
>     return multimap(lambda x: filter(func, x), s, n-1)
>
> def multireduce(func, s, n=2):
>     return multimap(lambda x: reduce(func, x), s, n-1)
>
> class nullfunc(object):
>     def __call__(self, *a, **k): return self
>     def __getattr(self, name): return getattr(None, name)

Could you describe what these functions do? Preferably with examples
that demonstrates that they are useful.

-- 
mvh Björn


More information about the Python-Dev mailing list