-
Notifications
You must be signed in to change notification settings - Fork 0
4. Curry
Carlos De Dios edited this page Oct 20, 2015
·
1 revision
Takes a function that receives n parameters and yields a function that will wait until n parameters are provided before invoking the original function.
/* Regular Approach */
let divide = (a, b) => a / b;
// divide(10) => undefined; divide(10, 2) => 5
let divideBy = (b) => (a) => a / b;
// divideBy(10) => Function; divideBy(2)(10) => 5
let halve = divideBy(2);
return halve(10);
/* Curry Approach */
let divide = curry((b, a) => a / b);
// divide(10) => Function; divide(2, 10) => 5; divide(2)(10) => 5
let halve = divide(2);
return halve(10);