Created
January 16, 2018 13:12
-
-
Save oliverturner/39ccd528a0d1e06c184c3e8ef5fec1b6 to your computer and use it in GitHub Desktop.
Pipe functionality without |> syntax
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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