# Obligatory set of small functions from toolz import accumulate def add(x, y): return x + y def mul(x, y): return x * y def fib(n): a, b = 0, 1 for i in range(n): a, b = b, a + b return b # We commonly use a lambda expression and the equals sign cumsum = lambda data: accumulate(add, data) # This is perfectly equivalent to the function definition def cumsum(data): return accumulate(add, data) # Or we can use the `partial` function from functools # Partial inserts an argument into the first place from functools import partial cumsum = partial(accumulate, add) # Semantically like the following: # cumsum(whatever) = accumulate(add, whatever) double = ... assert double(5) = 10 mul(2) from toolz import curry mul = curry(mul) mul(2) accumulate = curry(accumulate) map = curry(map) cumsum = accumulate(add) cumprod = accumulate(mul) fibMany = map(fib) fibMany(range(10)) from toolz.curried import map from toolz import map, curry map = curry(map)