import { InferType , IParallelEnumerable , OfType , ParallelGeneratorType } from "../../types" ; import { BasicParallelEnumerable } from "../BasicParallelEnumerable" ; import { nextIteration } from "./_nextIteration" ; import { typeDataToArray } from "./_typeDataToArray" ; param source param type returns export const ofType = < TSource , TType extends OfType > ( source , type ) : IParallelEnumerable < InferType < TType > > => { const typeCheck = typeof type === "string" ? ( x ) => [ typeof x === type , x as InferType < TType > ] : ( x ) => [ x instanceof ( type as any ) , x as InferType < TType > ] ; const generator = async ( ) => { const dataFunc = nextIteration ( source , typeCheck ) ; const values = await typeDataToArray ( dataFunc ) ; const filteredValues = [ ] ; for ( const [ pass , value ] of values ) { if ( pass ) { filteredValues . push ( value ) ; } } return filteredValues ; } ; return new BasicParallelEnumerable ( { generator , type : ParallelGeneratorType . PromiseToArray , } ) ; } ;