/* eslint-disable no-use-before-define */
/**
* @function curry
* @description Autocurries the provided function
*/
export default function curry (fun) {
const argslen = fun.length
if (argslen === 0) {
return fun
}
return createRecurser([])
function recurse (acc, args) {
const _acc = acc.concat(args)
return _acc.length < argslen
? createRecurser(_acc)
: fun.apply(this, _acc)
}
function createRecurser (acc) {
return function () {
return recurse(acc, Array.prototype.slice.call(arguments))
}
}
}