import type { IProc } from "./api.js" ; import { AProc } from "./aproc.js" ; /**
 * Composes the given  IProc s into a single new processor instance. The
 * returned `IProc` processes the given procs in serial (sequence), i.e. output
 * from 1st proc is used as input for 2nd etc.
 *
 *  remarks param a param b export function serial < A , B , C > ( a , b ) ; export function serial < A , B , C , D > ( a , b , c ) ; export function serial < A , B , C , D , E > ( a , b , c , d ) ; export function serial < A , B , C , D , E > ( a , b , c , d , ... xs ) ; export function serial ( ... procs ) { const [ a , b , c , d ] = procs ; switch ( procs . length ) { case 2 : return new Serial2 ( a , b ) ; case 3 : return new Serial3 ( a , b , c ) ; case 4 : return new Serial4 ( a , b , c , d ) ; default : return new Serial ( procs ) ; } } export class Serial2 < A , B , C > extends AProc < A , C > { constructor ( protected _a , protected _b ) { super ( < any > null ) ; } next ( x ) { return ( this . _val = this . _b . next ( this . _a . next ( x ) ) ) ; } } export class Serial3 < A , B , C , D > extends AProc < A , D > { constructor ( protected _a , protected _b , protected _c ) { super ( < any > null ) ; } next ( x ) { return ( this . _val = this . _c . next ( this . _b . next ( this . _a . next ( x ) ) ) ) ; } } export class Serial4 < A , B , C , D , E > extends AProc < A , E > { constructor ( protected _a , protected _b , protected _c , protected _d ) { super ( < any > null ) ; } next ( x ) { return ( this . _val = this . _d . next ( this . _c . next ( this . _b . next ( this . _a . next ( x ) ) ) ) ) ; } } export class Serial extends AProc < any , any > { constructor ( protected _procs ) { super ( < any > null ) ; } next ( x ) { return ( this . _val = this . _procs . reduce ( ( x , p ) => p . next ( x ) , x ) ) ; } }