Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // A contrived compose function.
- const compose = (f1, f2) => (...args) => f1(f2(...args));
- // These functions are curried. Instead of the usual (a, b) => a + b, we're supplying each parameter individually
- // and then returning a function that takes the next param.
- // This is currying. We're taking a function that normally has 2 params, and turning it into a function that takes 1 param,
- // then returns another function expecting the second param.
- const add = a => b => a + b;
- const multiply = a => b => a * b;
- // Let's build a new function by composing the above 2 and partially applying some values to them
- const addTwoThenDouble = compose(multiply(2), add(2));
- // Running this over the value 10 looks like this
- addTwoThenDouble(10) // outputs 24
Add Comment
Please, Sign In to add comment