Skip to content

Instantly share code, notes, and snippets.

@jossmac
Created April 18, 2018 01:29
Show Gist options
  • Save jossmac/6f125068d28f3c2c4e4f407962dd0eb3 to your computer and use it in GitHub Desktop.
Save jossmac/6f125068d28f3c2c4e4f407962dd0eb3 to your computer and use it in GitHub Desktop.
Helper function for composing functions together
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