Last active
January 16, 2020 14:32
-
-
Save lowderdev/ee0a313fe1533b41e96dd52ebbd00a36 to your computer and use it in GitHub Desktop.
JavaScript Pipe Condensed
This file contains hidden or 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 pipe = (...fns) => x => fns.reduce((y, f) => f(y), x); | |
const add3 = x => x + 3; | |
const times2 = x => x * 2; | |
const add3times2 = pipe(add3, times2); | |
const times2add3 = pipe(times2, add3); | |
console.log(add3times2(5)); // 16 | |
console.log(times2add3(5)); // 13 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment