import { fromAsync } from "../../async/static/fromAsync" ; import { IAsyncEnumerable } from "../../types" ; param source param selector returns export const selectManyAsync = < TSource , TResult > ( source , selector ) : IAsyncEnumerable < TResult > => { if ( selector . length === 1 ) { return selectManyAsync1 ( source , selector as ( x : TSource ) => Promise < Iterable < TResult > > ) ; } else { return selectManyAsync2 ( source , selector ) ; } } ; const selectManyAsync1 = < TSource , TResult > ( source , selector ) => { async function * generator ( ) { for ( const value of source ) { const innerValues = await selector ( value ) ; for ( const innerValue of innerValues ) { yield innerValue ; } } } return fromAsync ( generator ) ; } ; const selectManyAsync2 = < TSource , TResult > ( source , selector ) => { async function * generator ( ) { let index = 0 ; for ( const value of source ) { const innerValues = await selector ( value , index ) ; for ( const innerValue of innerValues ) { yield innerValue ; } index ++ ; } } return fromAsync ( generator ) ; } ;