Skip to content

Instantly share code, notes, and snippets.

@daronwolff
Created May 20, 2016 21:07
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 daronwolff/e9877b694bf56688b3e96567e7a7fe81 to your computer and use it in GitHub Desktop.
Save daronwolff/e9877b694bf56688b3e96567e7a7fe81 to your computer and use it in GitHub Desktop.
Write a function that takes a function and an argument, and returns a function that can supply a second argument add3 = curry(add,3); add3(4); // 7
var add = (function(a) {
return function(b) {
return a + b;
}
});
var mul = (function(a) {
return function(b) {
var total = a * b;
return total;
}
});
function curry(f, x) {
return f(x)
}
add3 = curry(add, 3);
console.log(add3(4)); // 7
var a = curry(add, 3)(3); // 6
var b = curry(mul, 5)(6); // 30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment