import type { FnAny } from "@thi.ng/api" ; import type { IGen , IProc } from "./api.js" ; import { MapG1 } from "./mapg.js" ; /**
 * Higher order generator. Composes a new  IGen from given source gen and
 * a number of  IProc s (processed in series, like using  serial ).
 *
 *  param src param proc export function pipe < A , B > ( src , proc ) ; export function pipe < A , B , C > ( src , a , b ) ; export function pipe < A , B , C , D > ( src , a , b , c ) ; export function pipe < A , B , C , D , E > ( src , a , b , c , d ) ; export function pipe < A , B , C , D , E > ( src , a , b , c , d , ... xs ) ; export function pipe ( src , ... procs ) { let fn ; const [ a , b , c , d ] = procs ; switch ( procs . length ) { case 1 : fn = ( x ) => a . next ( x ) ; break ; case 2 : fn = ( x ) => b . next ( a . next ( x ) ) ; break ; case 3 : fn = ( x ) => c . next ( b . next ( a . next ( x ) ) ) ; break ; case 4 : fn = ( x ) => d . next ( c . next ( b . next ( a . next ( x ) ) ) ) ; break ; default : fn = ( x ) => procs . reduce ( ( x , p ) => p . next ( x ) , x ) ; } return new MapG1 ( fn , src , < any > null ) ; }