Created
April 12, 2020 17:09
-
-
Save larizzatg/cda1e2b57fced4e7a0959e5ccea8826e to your computer and use it in GitHub Desktop.
Learning how to do a basic curry
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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