管道运营商是否会启用功能组合?
const sum = (nos)=> nos.reduce((p,c)=> p + (+c), 0);
const avg = (nos)=> sum(nos) / nos.length;
const tail = ([_, ...tail])=> tail;
const tailAndAverage = tail |> avg; // valid?
tailAndAverage
是上述代码中的函数吗?
答案 0 :(得分:3)
不 - 引用提案:
管道运算符本质上是一个带有单个参数的函数调用的有用语法糖。换句话说,sqrt(64)相当于64 |> SQRT。
所以你的例子实际上最终会贬低avg(tail)
,这不是你想要的。
尽管如此,还有两个单独的提案要在该语言中添加一个合成运算符: