Skip to content

Instantly share code, notes, and snippets.

@fabiancarlos
Created October 7, 2012 21:18
Show Gist options
  • Save fabiancarlos/3849635 to your computer and use it in GitHub Desktop.
Save fabiancarlos/3849635 to your computer and use it in GitHub Desktop.
Currying Examples
function Schonfinkelize(fn){
var slice = Array.prototype.slice;
var stored_args = slice.call(arguments, 1);
return function (){
var new_args = slice.call(arguments);
var args = stored_args.concat(new_args);
return fn.apply(null, args);
};
}
function add(){
return x + y;
}
var newadd = Schonfinkelize(add, 5);
newadd(4); // 9
Schonfinkelize(add, 6)(7); // 13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment