I have function that look like this:
function curry(fn) {
var args = [].slice.call(arguments, 1);
return function() {
return fn.call(this, args.concat([].slice.call(arguments)));
};
}
I always thought that's how the function should look like and should work as:
function add(a, b, c, d) {
return a+b+c+d;
}
curry(add, 1, 2)(3, 4);
but Wikipedia Article says that
it can be called as a chain of functions, each with a single argument
so the curry should look like this:
function curry(fn) {
var args = [];
return function curring() {
args = args.concat([].slice.call(arguments));
if (args.length >= fn.length) {
return fn.apply(this, args);
} else {
return curring;
}
};
}
and be used as this:
function add(a, b, c, d) {
return a+b+c+d;
}
curry(add)(1)(2)(3)(4);
Am I right?