Skip to content

Instantly share code, notes, and snippets.

@oliverturner
Created January 16, 2018 13:12
Show Gist options
  • Save oliverturner/39ccd528a0d1e06c184c3e8ef5fec1b6 to your computer and use it in GitHub Desktop.
Save oliverturner/39ccd528a0d1e06c184c3e8ef5fec1b6 to your computer and use it in GitHub Desktop.
Pipe functionality without |> syntax
const compose = (f, g) => (...args) => f(g(...args));
const pipe = (...fns) => fns.reduceRight(compose);
const double = a => a * 2
const square = a => a * a
const increment = a => a + 1
const maths = pipe(double, square, increment)
console.log(maths(2)) // => 17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment