Skip to content

Instantly share code, notes, and snippets.

@johnrees
Created January 4, 2018 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnrees/284dfe6de5b0cd162078dfb8045adf69 to your computer and use it in GitHub Desktop.
Save johnrees/284dfe6de5b0cd162078dfb8045adf69 to your computer and use it in GitHub Desktop.
const inc = (x) => x + 1
const dbl = (x) => x * 2
const add = (x, y) => x + y
const multiply = (x, y) => x * y
const subtract = (x, y) => x - y
const divide = (x, y) => x / y
const partial = (fn, ...args) => fn.bind(null, ...args)
const _pipe = (f, g) => (...args) => g(f(...args))
const pipe = (...fns) => fns.reduce(_pipe)
const pipeline = pipe(add, inc, dbl, inc)
console.log(pipeline(1, 2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment