Posted in Uncategorized

Tasty JavaScript Curry

JavaScript Curry:

A useful technique to partially evaluate functions.

Coming Soon…


function myFunc(a, b) {
if (arguments.length < 1) {
return myFunc;
} else if (arguments.length < 2) {
return function(c) { return a + c }
} else {
return a + b;
}
}

console.log(myFunc(2,2));

var add4 = myFunc(4);
console.log(add4);

console.log(add4(5));

var add = myFunc();
console.log(add);

var addTwo = add(5,6);
console.log(addTwo);

var addOne = add(1);
console.log(addOne(2));

Advertisements