Skip to content

Instantly share code, notes, and snippets.

@schell
Last active December 16, 2015 00:59
Show Gist options
  • Save schell/5351336 to your computer and use it in GitHub Desktop.
Save schell/5351336 to your computer and use it in GitHub Desktop.
Function currying using javascript.
function curry(f, arg) {
// Return a new curried function. Mmmm, spicy.
return function curriedFunction() {
// Take the other arguments and join them with our
// curried arg.
var args = Array.prototype.slice.call(arguments);
args.unshift(arg);
// Apply the function.
return f.apply(null, args);
};
}
// Example:
function concatStrings(front, back) {
return front + back;
}
var prefixWithFoo = curry(concatStrings, "Foo");
console.log(prefixWithFoo("Bat"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment