@web3r/flowerkit
Version:
A collection of more than 60 often used utility JS functions that simplify frontend development.
18 lines (17 loc) • 779 B
JavaScript
import ow from"ow";
/**
* Evaluating functions with multiple arguments and decomposing them into a sequence of functions with a specific number of arguments
* @param fn{Function} - source function
* @param arity{Number=} - arity of function
* @return {Function}
* @example
* // How to curry a function?
*
* function getSum(a, b) {
* return a + b;
* }
*
* const getCurriedSum = getCurryFn(getSum);
* curriedSum(1)(2); // 3
*/const getCurryFn=(fn,arity=fn.length)=>{ow(fn,ow.function);ow(arity,ow.number);return function nextCurry(previousArguments){return function curried(nextArgument){const args=[...previousArguments,nextArgument];if(args.length>=arity)return fn(...args);else return nextCurry(args)}}([])};export{getCurryFn};
//# sourceMappingURL=index.js.map