import { illegalArity } from "@thi.ng/errors/illegal-arity" ; import type { Fn , FnAny } from "@thi.ng/api" ; /**
 * Returns the right-to-left composition of given functions. I.e. when
 * the composed function is called, the given right most function is
 * called first (supports any number of args) and its return value then
 * used as sole argument for the next function etc. Eventually returns
 * result of left-most function.
 */ export function comp < A , B > ( a ) ; export function comp < A , B > ( a , b ) ; export function comp < A , B , C > ( a , b , c ) ; export function comp < A , B , C , D > ( a , b , c , d ) ; export function comp < A , B , C , D , E > ( a , b , c , d , e ) ; export function comp < A , B , C , D , E , F > ( a , b , c , d , e , f ) ; export function comp < A , B , C , D , E , F , G > ( a , b , c , d , e , f , g ) ; export function comp < A , B , C , D , E , F , G , H > ( a , b , c , d , e , f , g , h ) ; export function comp < A , B , C , D , E , F , G , H , I > ( a , b , c , d , e , f , g , h , i ) ; export function comp < A , B , C , D , E , F , G , H , I , J > ( a , b , c , d , e , f , g , h , i , j ) ; export function comp < A , B , C , D , E , F , G , H , I , J > ( a , b , c , d , e , f , g , h , i , j , ... fns ) ; export function comp ( ... fns ) { let [ a , b , c , d , e , f , g , h , i , j ] = fns ; switch ( fns . length ) { case 0 : illegalArity ( 0 ) ; case 1 : return a ; case 2 : return ( ... xs ) => a ( b ( ... xs ) ) ; case 3 : return ( ... xs ) => a ( b ( c ( ... xs ) ) ) ; case 4 : return ( ... xs ) => a ( b ( c ( d ( ... xs ) ) ) ) ; case 5 : return ( ... xs ) => a ( b ( c ( d ( e ( ... xs ) ) ) ) ) ; case 6 : return ( ... xs ) => a ( b ( c ( d ( e ( f ( ... xs ) ) ) ) ) ) ; case 7 : return ( ... xs ) => a ( b ( c ( d ( e ( f ( g ( ... xs ) ) ) ) ) ) ) ; case 8 : return ( ... xs ) => a ( b ( c ( d ( e ( f ( g ( h ( ... xs ) ) ) ) ) ) ) ) ; case 9 : return ( ... xs ) => a ( b ( c ( d ( e ( f ( g ( h ( i ( ... xs ) ) ) ) ) ) ) ) ) ; case 10 : default : const fn = ( ... xs ) => a ( b ( c ( d ( e ( f ( g ( h ( i ( j ( ... xs ) ) ) ) ) ) ) ) ) ) ; return fns . length === 10 ? fn : ( < any > comp ) ( fn , ... fns . slice ( 10 ) ) ; } } /**
 * Similar to  {@link (comp:1)} , but composes given functions in left-to-right order.
  export function compL < A > ( a ) ; export function compL < A , B > ( a , b ) ; export function compL < A , B , C > ( a , b , c ) ; export function compL < A , B , C , D > ( a , b , c , d ) ; export function compL < A , B , C , D , E > ( a , b , c , d , e ) ; export function compL < A , B , C , D , E , F > ( a , b , c , d , e , f ) ; export function compL < A , B , C , D , E , F , G > ( a , b , c , d , e , f , g ) ; export function compL < A , B , C , D , E , F , G , H > ( a , b , c , d , e , f , g , h ) ; export function compL < A , B , C , D , E , F , G , H , I > ( a , b , c , d , e , f , g , h , i ) ; export function compL < A , B , C , D , E , F , G , H , I , J > ( a , b , c , d , e , f , g , h , i , j ) ; export function compL < A , B , C , D , E , F , G , H , I , J > ( a , b , c , d , e , f , g , h , i , j , ... xs ) ; export function compL ( ... fns ) { return comp . apply ( null , < any > fns . reverse ( ) ) ; } deprecated renamed to  {@link (compL:1)} export const compI = compL ;