Skip to content

Instantly share code, notes, and snippets.

@mindevolution
Created June 10, 2019 07:39
Show Gist options
  • Save mindevolution/b9b2c970341095ebd1d890130f763a1a to your computer and use it in GitHub Desktop.
Save mindevolution/b9b2c970341095ebd1d890130f763a1a to your computer and use it in GitHub Desktop.
js curry
const curry = fn => {
if (fn.length <= 1) return fn;
const generator = (...args) => {
if (fn.length === args.length) {
return fn(...args);
} else {
return (...args2) => generator(...args, ...args2);
}
};
return generator;
};
const add = (a, b, c, d) => a + b + c + d;
const curriedAdd = curry(add);
const added = curriedAdd(5)(6)(7)(8);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment