import {flow, curry} from 'lodash';
const add = (a, b) => a + b;
const square = n => n * n;
const tap = curry((interceptor, n) => {
interceptor(n);
return n;
});
const trace2 = curry((message, n) => {
return tap((n) => console.log(`${message} is ${n}`), n);
});
const trace = label => {
return tap(x => console.log(`== ${ label }: ${ x }`));
};
const addSquare = flow([add, trace('after add'), square]);
console.log(addSquare(3, 1));
Run Code Online (Sandbox Code Playgroud)
我开始写跟踪2认为跟踪不起作用,因为"如何挖掘可能知道n或x什么?".
但跟踪确实有效,我不明白它如何能够"注入"来自流量的x进入点击呼叫.任何解释将不胜感激:)