compose 实现
function compose(...args) {
return (result) => {
return args.reduceRight((result, fn) => {
return fn(result)
}, result)
}
}
pipe 实现
function compose(...args) {
return (result) => {
return args.reduce((result, fn) => {
return fn(result)
}, result)
}
}
柯里化实现
function currying(fn, ...args) {
if (args.length >= fn.length) {
return fn(...args)
}
return function (...args2) {
return currying(fn, ...args, ...args2)
}
}
部分应用实现
function partial(fn, ...args) {
return (..._arg) => {
return fn(...args, ..._arg);
}
}