Skip to content

Instantly share code, notes, and snippets.

@larizzatg
Created April 12, 2020 17:09
Show Gist options
  • Save larizzatg/cda1e2b57fced4e7a0959e5ccea8826e to your computer and use it in GitHub Desktop.
Save larizzatg/cda1e2b57fced4e7a0959e5ccea8826e to your computer and use it in GitHub Desktop.
Learning how to do a basic curry
const _ = {};
const abc = function(a, b, c) {
return [a, b, c];
}
_.curry = (fn) => {
let arguments = [];
const getArgument = (...args) => {
arguments = arguments.concat(args);
arguments
return arguments.length < fn.length ? getArgument : fn(...arguments);
};
return getArgument;
}
const curriedOne = _.curry(abc);
const resultOne = curriedOne(1)(2)(3);
console.log(resultOne);
const curriedTwo = _.curry(abc);
const resultTwo = curriedTwo(1, 2)(3);
console.log(resultTwo);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment