1 | const mixCompose = (chain, func) => (chain instanceof Promise || typeof chain.then === 'function' ? chain.then(func) : func(chain));
|
2 |
|
3 | const pipe = (...fn) => input => fn.reduce(mixCompose, input);
|
4 | const compose = (...fn) => input => fn.reduceRight(mixCompose, input);
|
5 |
|
6 | const 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 | };
|
15 | module.exports = { pipe, compose, curry };
|