Skip to content

Instantly share code, notes, and snippets.

@manutuero
Created November 19, 2018 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manutuero/e841e7b3bb17ed5e62d828fbac1b2a8d to your computer and use it in GitHub Desktop.
Save manutuero/e841e7b3bb17ed5e62d828fbac1b2a8d to your computer and use it in GitHub Desktop.
A functional composition example in Javascript ES6.
/* Functional composition */
const greet = x => `Hello ${x}`; // f
const emote = x => `${x} :)`; // g
const compose = (f, g) => x => f(g(x)); // fog(x) = f[g(x)]
/* Use example */
compose(greet, emote)('Manu');
// "Hello Manu :)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment