Created
October 12, 2021 18:49
-
-
Save AD0791/fe2884efd5b866936c23b6106b554fd9 to your computer and use it in GitHub Desktop.
function composition
This file contains hidden or 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
import functools | |
def compose(*functions): | |
return functools.reduce(lambda f, g: lambda x: f(g(x)), functions) | |
# dec double inc are given function | |
>>> inc_double_and_dec = compose(dec, double, inc) | |
>>> inc_double_and_dec(10) | |
>>> 21 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment