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@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@python.org
http://mail.python.org/mailman/listinfo/python-ideas



--
Yuv
hzk.co.il