Created
November 24, 2020 21:55
-
-
Save manavm1990/48a917b0b8f87a402bf9966b75f66dc2 to your computer and use it in GitHub Desktop.
🍛ing fxn. based on Eric Elliott's Version
This file contains 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
// Keep collecting args... | |
const curry = (fxn, accumulatedArgs = []) => | |
// Collect fxn args | |
(...args) => | |
((currentArgs) => | |
// Do we have all of the args necessary to run the fxn? | |
currentArgs.length === fxn.length | |
? // If so, invoke the original function with the spread of our currentArgs | |
fxn(...currentArgs) | |
: // If not, keep 🍛ing with our Array of args | |
curry(fxn, currentArgs))( | |
// Invocation with accumulating args - currentArgs | |
[...accumulatedArgs, ...args] | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment