Skip to content

Instantly share code, notes, and snippets.

@obenjiro
Last active June 6, 2016 14:43
Show Gist options
  • Select an option

  • Save obenjiro/b0becab72178fbdca4f6 to your computer and use it in GitHub Desktop.

Select an option

Save obenjiro/b0becab72178fbdca4f6 to your computer and use it in GitHub Desktop.
One lame autoCurry implementation
function auto_curry(f) {
return function() {
var args = [];
args.push.apply(args, arguments);
var next = function() {
args.push.apply(args, arguments);
if (f.length === args.length) {
return f.apply(this, args);
} else {
return next;
}
};
if (f.length === args.length) {
return f.apply(this, args);
} else {
return next;
}
};
}
function sum(a,b){
return a + b;
}
var asum = auto_curry(sum);
document.body.innerHTML = asum(1)(4) + asum(1, 4);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment