compose
JavaScript
const compose = (...args) => {
return val => {
return args.reduce((accum, item) => {
return item(accum);
}, val);
}
};
const a = val => val + 2;
const b = val => val * 2;
const c = val => val + 1;
const func = compose(a, b, c);
console.error('func', func(1)); // 7