Skip to content

Instantly share code, notes, and snippets.

@chris-geelhoed
Last active March 2, 2020 23:23
Show Gist options
  • Save chris-geelhoed/f8e438aec9941426eafe8b0e31da835f to your computer and use it in GitHub Desktop.
Save chris-geelhoed/f8e438aec9941426eafe8b0e31da835f to your computer and use it in GitHub Desktop.
Pipe Function
const pipe = (...fns) => input => {
return fns.reduce((output, fn) => fn(output), input)
}
const reverse = string => string.split('').reverse().join('')
const exclaim = string => `${string}!`
pipe(
reverse,
string => string.toUpperCase(),
exclaim,
exclaim,
exclaim,
console.log
)('diarb')
// Instead of console.log(exclaim(exclaim(exclaim(reverse('diarb'.toUpperCase())))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment