I'm trying to translate my Javascript compose functions into Python but I'm having trouble with the last one. How can I generalize an unknown number of functions?
After reading this, I would like to avoid the reduce()
method.
javascript:
/* compose functions */
const comp1 = (fn2, fn1) => arr => fn2(fn1(arr)) // 2 functions, one array
const comp2 = (fn2, fn1) => (...arrs) => fn2(fn1(...arrs)) // 2 functions, multiple arrays
const comp3 = (...fns) => (...arrs) => fns.reduceRight((v,f) => f(v), arrs) // multiple functions, multiple arrays
python:
/* compose functions */
comp1 = lambda fn2,fn1: lambda arr: fn2(fn1(arr)) # 2 functions, 1 array
comp2 = lambda fn2,fn1: lambda *arrs: fn2(fn1(*arrs)) # 2 functions, multiple arrays
comp3 = lambda *fns: lambda *arrs: ????
all improvements are appreciated...