Created
March 31, 2014 16:18
-
-
Save mpkocher/9896022 to your computer and use it in GitHub Desktop.
compose functions in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def compose(*funcs): | |
"""Functional composition | |
[f, g, h] will be f(g(h(x))) | |
""" | |
def compose_two(f, g): | |
def c(x): | |
return f(g(x)) | |
return c | |
return functools.reduce(compose_two, funcs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example