Guest User

Untitled

a guest
Mar 24th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. const mul = (a, b = 2) => a * b;
  2.  
  3. const badlyCurriedMul = curry(mul);
  4. badlyCurriedMul(1) // 2, the curried function will use the default parameter immediately.
  5.  
  6. // And that's because mul.length is 1.
  7. console.log(mul.length); // 1
  8. // That's right, function length will not take default parameter into account
  9. // so we need to specify the correct length
  10. const curriedMul = curry(mul, 2);
  11. curriedMul(1); // fn ...
  12. curriedMul(1, 5); // 5
  13. // and now it work
Add Comment
Please, Sign In to add comment