Created
November 19, 2018 12:32
-
-
Save manutuero/e841e7b3bb17ed5e62d828fbac1b2a8d to your computer and use it in GitHub Desktop.
A functional composition example in Javascript ES6.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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