Message from JavaScript discussions

December 2017

— Made my compose a tiny one

— 

const compose = (initialValue, ...funcs) =>
funcs.reduce((value, func) => func(value), initialValue);

— The reduce doesn't really make it much tinier, but no assignment!!!

— Heh, left-to-right?

— 

const compose = (...funcs) =>
initialValue =>
funcs.reduce((value, func) =>
func(value), initialValue);

Message permanent page

— This

— 

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

— Yes

— Better