Skip to content

Instantly share code, notes, and snippets.

@minimal
Created June 30, 2009 23:09
Show Gist options
  • Save minimal/138490 to your computer and use it in GitHub Desktop.
Save minimal/138490 to your computer and use it in GitHub Desktop.
import functional
def MultiCompose(*funcs):
"""Return a function composed of many functions
MultiCompose(f, g, h) == f(g(h))
"""
return functional.partial(reduce, functional.compose)(funcs)
def ThreadFuncs(*funcs):
"""Thread funcs into eachother from left to right
ThreadFuncs(f, g, h) == h(g(f))
"""
return functional.partial(reduce, functional.compose)(reversed(funcs))
def thread_funcs(arg, *funcs):
"""Thread funcs into eachother from left to right and run func with
args
"""
return functional.partial(reduce, functional.compose)(reversed(funcs))(arg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment