* Create a function that composes multiple functions together. In a
* composition of functions, each function is given the next function
* as an argument and must call it to continue executing.
* const myComposedFunc = compose(
* myComposedFunc(0) // => 5
F1NextArgs extends any[],
next: (...args: F1NextArgs) => LastResult,
) => (...args: F1Args) => F1Result,
last: (...args: F1NextArgs) => LastResult,
): (...args: F1Args) => F1Result;
F1NextArgs extends any[],
F2NextArgs extends any[],
next: (...args: F1NextArgs) => F2Result,
) => (...args: F1Args) => F1Result,
next: (...args: F2NextArgs) => LastResult,
) => (...args: F1NextArgs) => F2Result,
last: (...args: F2NextArgs) => LastResult,
): (...args: F1Args) => F1Result;
F1NextArgs extends any[],
F2NextArgs extends any[],
F3NextArgs extends any[],
next: (...args: F1NextArgs) => F2Result,
) => (...args: F1Args) => F1Result,
next: (...args: F2NextArgs) => F3Result,
) => (...args: F1NextArgs) => F2Result,
next: (...args: F3NextArgs) => LastResult,
) => (...args: F2NextArgs) => F3Result,
last: (...args: F3NextArgs) => LastResult,
): (...args: F1Args) => F1Result;
F1NextArgs extends any[],
F2NextArgs extends any[],
F3NextArgs extends any[],
F4NextArgs extends any[],
next: (...args: F1NextArgs) => F2Result,
) => (...args: F1Args) => F1Result,
next: (...args: F2NextArgs) => F3Result,
) => (...args: F1NextArgs) => F2Result,
next: (...args: F3NextArgs) => F4Result,
) => (...args: F2NextArgs) => F3Result,
next: (...args: F4NextArgs) => LastResult,
) => (...args: F3NextArgs) => F4Result,
last: (...args: F4NextArgs) => LastResult,
): (...args: F1Args) => F1Result;
F1NextArgs extends any[],
F2NextArgs extends any[],
F3NextArgs extends any[],
F4NextArgs extends any[],
F5NextArgs extends any[],
next: (...args: F1NextArgs) => F2Result,
) => (...args: F1Args) => F1Result,
next: (...args: F2NextArgs) => F3Result,
) => (...args: F1NextArgs) => F2Result,
next: (...args: F3NextArgs) => F4Result,
) => (...args: F2NextArgs) => F3Result,
next: (...args: F4NextArgs) => F5Result,
) => (...args: F3NextArgs) => F4Result,
next: (...args: F5NextArgs) => LastResult,
) => (...args: F4NextArgs) => F5Result,
last: (...args: F5NextArgs) => LastResult,
): (...args: F1Args) => F1Result;
F1NextArgs extends any[],
F2NextArgs extends any[],
F3NextArgs extends any[],
F4NextArgs extends any[],
F5NextArgs extends any[],
F6NextArgs extends any[],
next: (...args: F1NextArgs) => F2Result,
) => (...args: F1Args) => F1Result,
next: (...args: F2NextArgs) => F3Result,
) => (...args: F1NextArgs) => F2Result,
next: (...args: F3NextArgs) => F4Result,
) => (...args: F2NextArgs) => F3Result,
next: (...args: F4NextArgs) => F5Result,
) => (...args: F3NextArgs) => F4Result,
next: (...args: F5NextArgs) => F6Result,
) => (...args: F4NextArgs) => F5Result,
next: (...args: F6NextArgs) => LastResult,
) => (...args: F5NextArgs) => F6Result,
last: (...args: F6NextArgs) => LastResult,
): (...args: F1Args) => F1Result;
F1NextArgs extends any[],
F2NextArgs extends any[],
F3NextArgs extends any[],
F4NextArgs extends any[],
F5NextArgs extends any[],
F6NextArgs extends any[],
F7NextArgs extends any[],
next: (...args: F1NextArgs) => F2Result,
) => (...args: F1Args) => F1Result,
next: (...args: F2NextArgs) => F3Result,
) => (...args: F1NextArgs) => F2Result,
next: (...args: F3NextArgs) => F4Result,
) => (...args: F2NextArgs) => F3Result,
next: (...args: F4NextArgs) => F5Result,
) => (...args: F3NextArgs) => F4Result,
next: (...args: F5NextArgs) => F6Result,
) => (...args: F4NextArgs) => F5Result,
next: (...args: F6NextArgs) => F7Result,
) => (...args: F5NextArgs) => F6Result,
next: (...args: F7NextArgs) => LastResult,
) => (...args: F6NextArgs) => F7Result,
last: (...args: F7NextArgs) => LastResult,
): (...args: F1Args) => F1Result;
F1NextArgs extends any[],
F2NextArgs extends any[],
F3NextArgs extends any[],
F4NextArgs extends any[],
F5NextArgs extends any[],
F6NextArgs extends any[],
F7NextArgs extends any[],
F8NextArgs extends any[],
next: (...args: F1NextArgs) => F2Result,
) => (...args: F1Args) => F1Result,
next: (...args: F2NextArgs) => F3Result,
) => (...args: F1NextArgs) => F2Result,
next: (...args: F3NextArgs) => F4Result,
) => (...args: F2NextArgs) => F3Result,
next: (...args: F4NextArgs) => F5Result,
) => (...args: F3NextArgs) => F4Result,
next: (...args: F5NextArgs) => F6Result,
) => (...args: F4NextArgs) => F5Result,
next: (...args: F6NextArgs) => F7Result,
) => (...args: F5NextArgs) => F6Result,
next: (...args: F7NextArgs) => LastResult,
) => (...args: F6NextArgs) => F7Result,
next: (...args: F8NextArgs) => LastResult,
) => (...args: F7NextArgs) => F8Result,
last: (...args: F8NextArgs) => LastResult,
): (...args: F1Args) => F1Result;
F1NextArgs extends any[],
F2NextArgs extends any[],
F3NextArgs extends any[],
F4NextArgs extends any[],
F5NextArgs extends any[],
F6NextArgs extends any[],
F7NextArgs extends any[],
F8NextArgs extends any[],
F9NextArgs extends any[],
next: (...args: F1NextArgs) => F2Result,
) => (...args: F1Args) => F1Result,
next: (...args: F2NextArgs) => F3Result,
) => (...args: F1NextArgs) => F2Result,
next: (...args: F3NextArgs) => F4Result,
) => (...args: F2NextArgs) => F3Result,
next: (...args: F4NextArgs) => F5Result,
) => (...args: F3NextArgs) => F4Result,
next: (...args: F5NextArgs) => F6Result,
) => (...args: F4NextArgs) => F5Result,
next: (...args: F6NextArgs) => F7Result,
) => (...args: F5NextArgs) => F6Result,
next: (...args: F7NextArgs) => LastResult,
) => (...args: F6NextArgs) => F7Result,
next: (...args: F8NextArgs) => LastResult,
) => (...args: F7NextArgs) => F8Result,
next: (...args: F9NextArgs) => LastResult,
) => (...args: F8NextArgs) => F9Result,
last: (...args: F9NextArgs) => LastResult,
): (...args: F1Args) => F1Result;
export function compose(...funcs: ((...args: any[]) => any)[]) {
return funcs.reverse().reduce((acc, fn) => fn(acc));