3 ms·
The first one is the signature my helper library, yunobuiltin, uses. def compose(*fns): """ compose(foo, bar, baz)(x) = foo(bar(baz(x))) """
by emidln 10y ago
The first one is the signature my helper library, yunobuiltin, uses.
def compose(*fns):
""" compose(foo, bar, baz)(x) = foo(bar(baz(x))) """
return reduce(lambda f, g: lambda *xs, **ys: f(g(*xs, **ys)), fns)
I also define `pipeline()` (which is `compose()`, but reversing the order of execution) and `thread()` which is like `pipeline()`, but the first value is immediately fed to the remaining *args which should be callables.