箭头版
const pipeline = (...funcs) =>
val => funcs.reduce((a, b) => b(a), val);
const plus1 = a => a + 1;
const mult2 = a => a * 2;
const addThenMult = pipeline(plus1, mult2);
addThenMult(5)
普通版
const plus1 = a => a + 1;
const mult2 = a => a * 2;
mult2(plus1(5))
// 12
网友评论