Skip to content

Instantly share code, notes, and snippets.

@harunyasar
Created March 10, 2017 12:07
Show Gist options
  • Save harunyasar/f3b94a1b52c7b9e71623951738099381 to your computer and use it in GitHub Desktop.
Save harunyasar/f3b94a1b52c7b9e71623951738099381 to your computer and use it in GitHub Desktop.
Example of function composition with Python
def addition(x):
return x + 5
def subtraction(y):
return y - 1
def compose(*funcs):
return lambda x: reduce(lambda v, f: f(v), reversed(funcs), x)
c = compose(addition, subtraction)
print(c(10)) # 14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment