I have an array of functions and I\'m trying to produce one function which consists of the composition of the elements in my array. My approach is:
def compo
One liner:
compose = lambda *F: reduce(lambda f, g: lambda x: f(g(x)), F)
Example usage:
f1 = lambda x: x+3 f2 = lambda x: x*2 f3 = lambda x: x-1 g = compose(f1, f2, f3) assert(g(7) == 15)