Created
June 15, 2016 01:30
-
-
Save fernandocanizo/399f62aa0684ee59c45e89fa532a26ab to your computer and use it in GitHub Desktop.
Using reduce to apply a pipeline of functions
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
"use strict"; | |
const pipe = functions => data => { | |
return functions.reduce((value, func) => func(value), data); | |
}; | |
const pipeline = pipe([ | |
n => n + 1, | |
n => n * 2, | |
n => n * n, | |
]); | |
pipeline(5); // 144 | |
pipeline(1); // 16 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Poor man curry?