Skip to content

Instantly share code, notes, and snippets.

@marty-wang
Created July 5, 2016 04:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marty-wang/c4b0b76bd3b9e228bc3cb79c5cfb65a1 to your computer and use it in GitHub Desktop.
Save marty-wang/c4b0b76bd3b9e228bc3cb79c5cfb65a1 to your computer and use it in GitHub Desktop.
Very small compose function
const compose = (...fns) => (...args) => fns.reduceRight((input, fn) => fn.apply(null, [].concat(input)), args)
const combine = (...args) => args.join(" ")
const shout = (x) => x.toUpperCase()
const emphasize = (x) => `${x}!`
const yell = compose(emphasize, shout, combine)
console.log(yell("hello", "world")); // "HELLO WORLD!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment