Skip to content

Instantly share code, notes, and snippets.

@getdave
Created May 31, 2017 10:40
Show Gist options
  • Save getdave/6fe257f0daed2c932736b0dcfdee7bd8 to your computer and use it in GitHub Desktop.
Save getdave/6fe257f0daed2c932736b0dcfdee7bd8 to your computer and use it in GitHub Desktop.
A quick demonstration of the use of a pipe function
const pipe = (...funcs) => seed => {
return funcs.reduce( (acc, func) => {
return func(acc);
}, seed);
}
const reverseWord = (val) => {
return val.split("").reverse().join('');
};
const convertToUpperCase = (val) => {
return val.toUpperCase();
};
const reverseCapitalise = pipe(
reverseWord,
convertToUpperCase
);
const result = reverseCapitalise('Hello world');
console.log(result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment