— The reduce
doesn't really make it much tinier, but no assignment!!!
—
const compose = (...funcs) =>
initialValue =>
funcs.reduce((value, func) =>
func(value), initialValue);
Message permanent page
—
myMath = compose(add(3), multiply(4));
myMath(2); // 20
— I prefer it but there is also another reduce function builtin that goes the other way
— And yes I'm aware of returning a function, the alternative being wrapping it in your own
—
const compose = (...funcs) =>
initValue =>
funcs.reduce((value, func) => func(value), initValue);
there
Message permanent page