Guest User

Untitled

a guest
Aug 17th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. // A contrived compose function.
  2. const compose = (f1, f2) => (...args) => f1(f2(...args));
  3.  
  4. // These functions are curried. Instead of the usual (a, b) => a + b, we're supplying each parameter individually
  5. // and then returning a function that takes the next param.
  6. // This is currying. We're taking a function that normally has 2 params, and turning it into a function that takes 1 param,
  7. // then returns another function expecting the second param.
  8. const add = a => b => a + b;
  9. const multiply = a => b => a * b;
  10.  
  11.  
  12. // Let's build a new function by composing the above 2 and partially applying some values to them
  13. const addTwoThenDouble = compose(multiply(2), add(2));
  14.  
  15. // Running this over the value 10 looks like this
  16. addTwoThenDouble(10) // outputs 24
Add Comment
Please, Sign In to add comment