my-idlers/node_modules/compose-function/module/index.js
cp6 fd22b0bf58 V2 (Laravel re-make)
V2 (Laravel re-make)
2022-03-06 02:02:12 +11:00

24 lines
457 B
JavaScript
Vendored

import arityN from 'arity-n';
let compose2 = (f, g) => (...args) => f(g(...args));
export default function compose(...functions) {
const funcs = functions.filter(fn => typeof fn === 'function');
let lastIdx = funcs.length - 1;
let arity = 0;
if (funcs.length <= 0) {
throw new Error('No funcs passed');
}
if (lastIdx >= 0 && funcs[lastIdx]) {
arity = funcs[lastIdx].length;
}
return arityN(funcs.reduce(compose2), arity);
}