import { IParallelEnumerable , ParallelGeneratorType } from "../../types" ; import { BasicParallelEnumerable } from "../BasicParallelEnumerable" ; import { nextIterationWithIndexAsync } from "./_nextIterationWithIndexAsync" ; import { typeDataToArray } from "./_typeDataToArray" ; param source param predicate returns export const whereAsync = < TSource > ( source , predicate ) => { const generator = async ( ) => { const dataFunc = nextIterationWithIndexAsync ( source , async ( value , index ) => { const keep = await predicate ( value , index ) ; return [ keep , value ] as [ boolean , TSource ] ; } ) ; const valuesAsync = await typeDataToArray ( dataFunc ) ; const filteredValues = [ ] ; for ( const [ keep , value ] of valuesAsync ) { if ( keep ) { filteredValues . push ( value ) ; } } return filteredValues ; } ; return new BasicParallelEnumerable ( { generator , type : ParallelGeneratorType . PromiseToArray , } ) ; } ;