import { Middleware , Handler , Func } from './types' ; export function middlewareReducer < TEvent , TContext , TResult , TIntermediateEvent , TIntermediateContext , TIntermediateResult , TNextEvent , TNextContext , TNextResult > ( previous , current ) { return ( next ) => previous ( current ( next ) ) ; } returns export function composeMiddleware < TEvent , TContext , TResult > ( ) ; param middleware returns export function composeMiddleware < TEvent , TContext , TResult , TNextEvent , TNextContext , TNextResult > ( middleware ) ; export function composeMiddleware < TEvent , TContext , TResult , TIntermediateEvent , TIntermediateContext , TIntermediateResult , TNextEvent , TNextContext , TNextResult > ( middleware1 , middleware2 ) ; export function composeMiddleware < TEvent , TContext , TResult , TIntermediateEvent1 , TIntermediateContext1 , TIntermediateResult1 , TIntermediateEvent2 , TIntermediateContext2 , TIntermediateResult2 , TNextEvent , TNextContext , TNextResult > ( middleware1 , middleware2 , middleware3 ) ; export function composeMiddleware < TEvent , TContext , TResult , TIntermediateEvent1 , TIntermediateContext1 , TIntermediateResult1 , TIntermediateEvent2 , TIntermediateContext2 , TIntermediateResult2 , TIntermediateEvent3 , TIntermediateContext3 , TIntermediateResult3 , TNextEvent , TNextContext , TNextResult > ( middleware1 , middleware2 , middleware3 , middleware4 ) ; export function composeMiddleware < TEvent , TContext , TResult , TIntermediateEvent1 , TIntermediateContext1 , TIntermediateResult1 , TIntermediateEvent2 , TIntermediateContext2 , TIntermediateResult2 , TIntermediateEvent3 , TIntermediateContext3 , TIntermediateResult3 , TIntermediateEvent4 , TIntermediateContext4 , TIntermediateResult4 , TNextEvent , TNextContext , TNextResult > ( middleware1 , middleware2 , middleware3 , middleware4 , middleware5 ) ; export function composeMiddleware < TEvent , TContext , TResult , TIntermediateEvent1 , TIntermediateContext1 , TIntermediateResult1 , TIntermediateEvent2 , TIntermediateContext2 , TIntermediateResult2 , TIntermediateEvent3 , TIntermediateContext3 , TIntermediateResult3 , TIntermediateEvent4 , TIntermediateContext4 , TIntermediateResult4 , TIntermediateEvent5 , TIntermediateContext5 , TIntermediateResult5 , TNextEvent , TNextContext , TNextResult > ( middleware1 , middleware2 , middleware3 , middleware4 , middleware5 , middleware6 ) ; export function composeMiddleware < TEvent , TContext , TResult , TIntermediateEvent1 , TIntermediateContext1 , TIntermediateResult1 , TIntermediateEvent2 , TIntermediateContext2 , TIntermediateResult2 , TIntermediateEvent3 , TIntermediateContext3 , TIntermediateResult3 , TIntermediateEvent4 , TIntermediateContext4 , TIntermediateResult4 , TIntermediateEvent5 , TIntermediateContext5 , TIntermediateResult5 , TIntermediateEvent6 , TIntermediateContext6 , TIntermediateResult6 , TNextEvent , TNextContext , TNextResult > ( middleware1 , middleware2 , middleware3 , middleware4 , middleware5 , middleware6 , middleware7 ) ; export function composeMiddleware < TEvent , TContext , TResult > ( middleware1 , ... restMiddlewares ) ; export function composeMiddleware < TEvent , TContext , TResult > ( ... middlewares ) ; export function composeMiddleware < TEvent , TContext , TResult > ( ... middlewares ) { return middlewares . reduce ( middlewareReducer , ( next ) => next ) ; } export function compose ( ) ; export function compose < TFunc extends Function > ( f ) ; export function compose < TIntermediate , TArgs extends unknown [ ] , TReturn > ( func1 , func2 ) ; export function compose < TIntermediate1 , TIntermediate2 , TArgs extends unknown [ ] , TReturn > ( func1 , func2 , func3 ) ; export function compose < TIntermediate1 , TIntermediate2 , TIntermediate3 , TArgs extends unknown [ ] , TReturn > ( func1 , func2 , func3 , func4 ) ; export function compose < TIntermediate1 , TIntermediate2 , TIntermediate3 , TIntermediate4 , TIntermediate5 , TIntermediate6 , TArgs extends unknown [ ] , TReturn > ( func1 , func2 , func3 , func4 , func5 ) ; export function compose < TIntermediate1 , TIntermediate2 , TIntermediate3 , TIntermediate4 , TIntermediate5 , TArgs extends unknown [ ] , TReturn > ( func1 , func2 , func3 , func4 , func5 , func6 ) ; export function compose < TIntermediate1 , TIntermediate2 , TIntermediate3 , TIntermediate4 , TIntermediate5 , TIntermediate6 , TArgs extends unknown [ ] , TReturn > ( func1 , func2 , func3 , func4 , func5 , func6 , func7 ) ; export function compose < T > ( func1 , ... funcs ) ; export function compose < T > ( ... funcs ) ; export function compose ( ... funcs ) { if ( funcs . length === 0 ) { return < T > ( arg ) => arg ; } if ( funcs . length === 1 ) { return funcs [ 0 ] ; } return funcs . reduce ( ( a , b ) => ( ... args ) => a ( b ( ... args ) ) ) ; }