Created
January 22, 2018 15:45
-
-
Save JakeTheCorn/3bac69a2eaff99c93ac36c09908dd22a to your computer and use it in GitHub Desktop.
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
// https://gist.github.com/JamieMason/172460a36a0eaef24233e6edb2706f83#file-es6-compose-md | |
// By: Jamie Mason | |
// https://gist.github.com/JamieMason | |
const compose = (...fns) => | |
fns.reverse().reduce((prevFn, nextFn) => | |
value => nextFn(prevFn(value)), | |
value => value | |
); | |
const example = compose( | |
val => { console.log(1); return `1<${val}>`; }, | |
val => { console.log(2); return `2<${val}>`; }, | |
val => { console.log(3); return `3<${val}>`; } | |
); | |
example('hello'); | |
/* OUTPUT TO CONSOLE => | |
3 | |
2 | |
1 | |
"1<2<3<hello>>>" | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment