Composing functions in Python
This is a very nice snippet to compose functions using functools
import functools
def compose(*functions):
'''
Compose an arbitary amount of functions into a single function
Source: https://mathieularose.com/function-composition-in-python
'''
def comp(f, g):
return lambda x: f(g(x))
return functools.reduce(comp, functions, lambda x: x)