You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

16 lines
486 B

/**
* Function to curry any javascript method
* @param {Function} fn - the target function we want to curry
* @param {...[args]} acc - initial arguments
* @returns {Function|*} it will return a function until the target function
* will receive all of its arguments
*/
export default function curry(fn, ...acc) {
return (...args) => {
args = [...acc, ...args]
return args.length < fn.length ?
curry(fn, ...args) :
fn(...args)
}
}