Skip to content

Instantly share code, notes, and snippets.

@DayBr3ak
Last active April 23, 2018 12:40
Show Gist options
  • Save DayBr3ak/0e392a3757e84abcea09d2b36bae8e78 to your computer and use it in GitHub Desktop.
Save DayBr3ak/0e392a3757e84abcea09d2b36bae8e78 to your computer and use it in GitHub Desktop.
Js Es6 Auto Currying
/** cu - auto currying function
*
* @param {function} fn the function to autocurry
* @param {integer} argc the number of args to autocurry if reflection is not possible
*/
function cu(fn, argc = null) {
const len = argc || fn.length;
const makeStack = (argsStack = []) => (...n) => {
const args = argsStack.concat(n);
if (args.length >= len) {
return fn(...args);
}
return makeStack(args);
};
return makeStack()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment