UNPKG

624 BJavaScriptView Raw
1const mixCompose = (chain, func) => (chain instanceof Promise || typeof chain.then === 'function' ? chain.then(func) : func(chain));
2
3const pipe = (...fn) => input => fn.reduce(mixCompose, input);
4const compose = (...fn) => input => fn.reduceRight(mixCompose, input);
5
6const curry = f => {
7 if (typeof f !== 'function') {
8 throw new Error(`curry requires a function, [${typeof f}] passed`);
9 }
10 return function currify() {
11 const args = Array.prototype.slice.call(arguments);
12 return args.length >= f.length ? f.apply(null, args) : currify.bind(null, ...args);
13 };
14};
15module.exports = { pipe, compose, curry };