Clojure style function "threading" in Python
Or possibly use the reduce function in the following way:
reduce(lambda x,f : f(x), [f1,f2,f3], arg)
Building on Howard's solution:
def T(*args):
return reduce(lambda l, r: r(l), args)
def dbl(n):
return 2*n
T(5,dbl,dbl)
#=> 20
T(5,dbl,dbl,lambda x: 3*x)
#=> 60
You can easily implement something like this yourself.
def compose(current_value, *args):
for func in args:
current_value = func(current_value)
return current_value
def double(n):
return 2*n
print compose(5, double, double) # prints 20
Or try https://mdk.fr/blog/pipe-infix-syntax-for-python.html A module that provide a syntax like :
fib() | take_while(lambda x: x < 1000000)
| where(lambda x: x % 2)
| select(lambda x: x * x)
| sum()