A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2007-April/072624.html below:

[Python-Dev] Some new additions to functools

[Python-Dev] Some new additions to functoolsPaul Hankin paul.hankin at pobox.com
Sun Apr 15 22:11:23 CEST 2007
On 4/15/07, SevenInchBread <adamadamadamamiadam at gmail.com> wrote:
> So I've cooked up some very simple functions to add to functools - to expand
> it into a more general-purpose module.
>
> def cat(x): return x
>
> class nullfunc(object):
>     def __call__(self, *args, **kargs): return self
>     def __getattr__(self, name):        return getattr(None, name)
>
> def multimap(func, seq, n=2):
>     assert n > 0, "n must be positive"
>     if n == 1: return map(func, seq)
>     else:       return map(lambda x: multimap(func, x, n-1), seq)
>
> def multifilter(func, seq, n=2):
>     return multimap(lambda x: filter(func, x), seq, n-1)
>
> def multireduce(func, seq, n=2):
>     return multimap(lambda x: reduce(func, x), seq, n-1)

-0 for cat (renamed to 'identity'), -1 for the rest.

I've occasionally wanted multimap but only in the default
case where it is simpler to be explicit.

-- 
Paul Hankin
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4