function curry(fn, ...restArgs){
let _restArgs = restArgs || [];
let len = fn.length;
let _this = this;
return function(){
let newArgs = [..._restArgs, ...Array.from(arguments)];
if(newArgs.length < len){
return curry.call(_this, fn, newArgs);
}else{
return fn.apply(this, newArgs);
}
}
}
function unCurry(fn) {
return function(...args){
args.forEach(item => {
if(typeof item !== 'function'){
return;
}else{
fn = fn(item);
}
return fn;
})
}
}
网友评论