Skip to content

Instantly share code, notes, and snippets.

@manavm1990
Created November 24, 2020 21:55
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 manavm1990/48a917b0b8f87a402bf9966b75f66dc2 to your computer and use it in GitHub Desktop.
Save manavm1990/48a917b0b8f87a402bf9966b75f66dc2 to your computer and use it in GitHub Desktop.
🍛ing fxn. based on Eric Elliott's Version
// 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