/* @flow strict */ /* eslint-disable */ /** * Composes single-argument functions from right to left. The rightmost * function can take multiple arguments as it provides the signature for * the resulting composite function. * * @param {...Function} funcs The functions to compose. * @returns {Function} A function obtained by composing the argument functions * from right to left. For example, compose(f, g, h) is identical to doing * (...args) => f(g(h(...args))). */ function composeImpl(...funcs) { if (funcs.length === 0) { return arg => arg; } const last = funcs[funcs.length - 1]; const rest = funcs.slice(0, -1); return (...args) => rest.reduceRight((composed, f) => f(composed), last(...args)); } type FN = (a: A) => R; const compose: ((end: void) => ((x: T) => T)) & ((m1: FN, end: void) => FN) & ((m1: FN, m2: FN, end: void) => FN) & ((m1: FN, m2: FN, m3: FN, end: void) => FN) & ((m1: FN, m2: FN, m3: FN, m4: FN, end: void) => FN) & ((m1: FN, m2: FN, m3: FN, m4: FN, m5: FN, end: void) => FN) & ((m1: FN, m2: FN, m3: FN, m4: FN, m5: FN, m6: FN, end: void) => FN) & ((m1: FN, m2: FN, m3: FN, m4: FN, m5: FN, m6: FN, m7: FN, end: void) => FN) & ((m1: FN, m2: FN, m3: FN, m4: FN, m5: FN, m6: FN, m7: FN, m8: FN, end: void) => FN) & ((m1: FN, m2: FN, m3: FN, m4: FN, m5: FN, m6: FN, m7: FN, m8: FN, m9: FN, end: void) => FN) & ((m1: FN, m2: FN, m3: FN, m4: FN, m5: FN, m6: FN, m7: FN, m8: FN, m9: FN, m10: FN, end: void) => FN) & ((...funcs: Array>) => FN) = (composeImpl: any); export default compose;