Created
April 18, 2018 01:29
-
-
Save jossmac/6f125068d28f3c2c4e4f407962dd0eb3 to your computer and use it in GitHub Desktop.
Helper function for composing functions together
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
function pipe(...fns) { | |
return param => fns.reduce( | |
(result, fn) => fn(result), | |
param | |
) | |
} | |
/* | |
The above function takes a list of functions and returns a function that can | |
apply the list from left to right, starting with a given parameter and then | |
passing the result of each function in the list to the next function in the list. | |
function saveUser(userInfo) { | |
return pipe( | |
validate, | |
normalize, | |
persist | |
)(userInfo) | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment