[Python-ideas] data structures should have an .any() method

Yuvgoog Greenle ubershmekel at gmail.com
Sat Sep 5 18:45:44 CEST 2009


I can't stand map/reduce/lambda... *instant readable makeover*def
minicomp(f1, f2):
    def comped(*args, **kwargs):
        return f1(f2(*args, **kwargs))
    return comped

def compose(*funcs):
    total = funcs[0]
    for f in funcs[1:]:
        total = minicomp(total, f)
    return total

On Sat, Sep 5, 2009 at 5:15 PM, Masklinn <masklinn at masklinn.net> wrote:

> On 5 Sep 2009, at 15:47 , Gerald Britton wrote:
> Ah -- so not a real function then (yet)?  Though something we could
>
>> borrow from Haskell, I suppose, even though:
>>
>> compose(foo,bar) == lambda x: foo(bar(x))
>>
>> no?
>>
>>
> Yeah but you could leverage Python's *args to get a compositor of more than
> two functions e.g.
>
>   def compose(*funcs):
>       return reduce(lambda f1, f2:
>                         lambda *args, **kwargs:
>                             f1(f2(*args, **kwargs)),
>                     funcs)
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>



-- 
Yuv
hzk.co.il
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20090905/589a2864/attachment.html>


More information about the Python-ideas mailing list