import type { L } from 'ts-toolbelt' ; const skip = Symbol ( 'skip' ) ; function transduceSync < L extends L . List < I > , I , R > ( list , transformer ) { const transduced = [ ] as R [ ] ; for ( let i = 0 ; i < list . length ; ++ i ) { const transformed = transformer ( list [ i ] ) ; if ( transformed !== skip ) { transduced [ transduced . length ] = transformed ; } } return transduced ; } async function transduceAsync < L extends L . List < I > , I , R > ( list , transformer ) { const transduced = [ ] as R [ ] ; for ( let i = 0 ; i < list . length ; ++ i ) { const transformed = await transformer ( list [ i ] ) ; if ( transformed !== skip ) { transduced [ transduced . length ] = transformed ; } } return transduced ; } const Filter = < I > ( filter ) => ( item ) => { return filter ( item ) ? item : ( skip as never ) ; } ; const Mapper = < I , R > ( mapper ) => ( item ) => { return mapper ( item ) ; } ; see https param list param transformer returns example const transduce = transduceSync as typeof transduceSync & { async : typeof transduceAsync ; } ; transduce . async = transduceAsync ; export { transduce , Filter , Mapper , skip } ;