Skip to content

Instantly share code, notes, and snippets.

@gt3
Last active May 25, 2017 04:05
Show Gist options
  • Select an option

  • Save gt3/24ea3813878ee01d9221e5e64bfb0efb to your computer and use it in GitHub Desktop.

Select an option

Save gt3/24ea3813878ee01d9221e5e64bfb0efb to your computer and use it in GitHub Desktop.
function pipe(...fns) {
function invoke(v) {
return fns.reduce((acc, fn) => (fn ? fn.call(this, acc) : acc), v)
}
return invoke
}
let i=1, fn = m => console.log(i++,m)
let piped = pipe.bind(null, fn)
piped = piped.bind(null, fn)
piped.bind(null, fn)()('xxx') //piped.bind(null, fn)('xxx') will just return invoke fn!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment