Skip to content

Instantly share code, notes, and snippets.

@tdd
Created February 3, 2015 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tdd/73ab0ebc2ea41893361e to your computer and use it in GitHub Desktop.
Save tdd/73ab0ebc2ea41893361e to your computer and use it in GitHub Desktop.
Partial application
function add(a, b, c) {
return a + b + c;
}
function partial(fx) {
var initial = Array.prototype.slice.call(arguments, 1);
return function() {
var args = Array.prototype.slice.call(arguments);
return fx.apply(this, initial.concat(args));
};
}
var add22 = partial(add, 2, 20);
add22(20);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment