管道操作
const addTen = pipe(
addOne,
addTwo,
addThree,
addFour
)
const pipe = ...args => x =>
args.reduce(
(outputValue, currentFunction) => currentFunction(outputValue),
x
)
// todo
// 基于prototype的这种链式操作
[1, 2, 3, 3, 5]
.map(i => i * 2)
.filter(i => i !== 10)
.reduce((acc, cur) => acc + cur)
a |> b // b(a)
{
"plugins": [["@babel/plugin-proposal-pipeline-operator", { "proposal": "minimal" }]]
}
import * as R from 'ramda'
[1, 2, 3, 4, 5]
|> R.map(i => i * 2)
|> R.uniq
|> R.filter(i => i !== 10)
|> R.reduce(R.add, 0)
// 是的,我们还可以写arrow function,
|> (_ => 'done, result is ' + _)
|> console.log