Skip to content

Latest commit

 

History

History
45 lines (44 loc) · 795 Bytes

pip.md

File metadata and controls

45 lines (44 loc) · 795 Bytes

pip

管道操作

const addTen = pipe(
  addOne,
  addTwo,
  addThree,
  addFour
)
const pipe = ...args => x => 
  args.reduce(
    (outputValue, currentFunction) => currentFunction(outputValue),
    x
  )

Pipe和Prototype

// todo
// 基于prototype的这种链式操作
[1, 2, 3, 3, 5]
  .map(i => i * 2)
  .filter(i => i !== 10)
  .reduce((acc, cur) => acc + cur)

js Proposal-pipeline-operator

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