import { fromAsync } from "../../async/static/fromAsync" ; import { IAsyncEnumerable } from "../../types" ; param source param predicate returns export const whereAsync = < TSource > ( source , predicate ) : IAsyncEnumerable < TSource > => { if ( predicate . length === 1 ) { return whereAsync1 ( source , predicate as ( x : TSource ) => Promise < boolean > ) ; } else { return whereAsync2 ( source , predicate ) ; } } ; const whereAsync1 = < T > ( source , predicate ) : IAsyncEnumerable < T > => { async function * generator ( ) { for ( const item of source ) { if ( await predicate ( item ) === true ) { yield item ; } } } return fromAsync ( generator ) ; } ; const whereAsync2 = < T > ( source , predicate ) : IAsyncEnumerable < T > => { async function * generator ( ) { let i = 0 ; for ( const item of source ) { if ( await predicate ( item , i ++ ) === true ) { yield item ; } } } return fromAsync ( generator ) ; } ;