我正在尝试编写一个'pipe'函数,这在Javascript中非常简单:
const pipe = (...funcs) => val => (
funcs.reduce((acc, func) => func(acc), val)
)
用法示例:
const sqrt = v => Math.sqrt(v);
const half = v => v / 2;
const plusFive = v => v + 5;
plusFive(half(sqrt(16))); // 7
const doStuff = pipe(sqrt, half, plusFive);
doStuff(16); // 7
如何在Rust中做同样的事情?谢谢!