import { IAsyncEnumerable } from "../../types" ; import { BasicAsyncEnumerable } from "../BasicAsyncEnumerable" ; type SelectAsyncFunc = { param source param selector returns < TSource , TResult > ( source , selector ) : IAsyncEnumerable < TResult > ; param source param key returns < TSource extends { [ key ] : Promise < any > ; } , TKey extends keyof TSource > ( source , key ) : IAsyncEnumerable < TSource [ TKey ] > ; } ; export const selectAsync = < TSource extends { [ key ] : Promise < TResult > ; } , TKey extends keyof TSource , TResult > ( source , selector ) : IAsyncEnumerable < any > => { if ( typeof selector === "string" ) { return selectAsync2 ( source , selector ) ; } else { return selectAsync1 ( source , selector as ( x : TSource ) => Promise < TResult > ) ; } } ; const selectAsync1 = < TSource , TResult > ( source , selector ) : IAsyncEnumerable < TResult > => { async function * iterator ( ) { for await ( const value of source ) { yield selector ( value ) ; } } return new BasicAsyncEnumerable ( iterator ) ; } ; const selectAsync2 = < TSource extends { [ key ] : Promise < TResult > ; } , TKey extends keyof TSource , TResult > ( source , key ) : IAsyncEnumerable < TResult > => { async function * iterator ( ) { for await ( const value of source ) { yield value [ key ] ; } } return new BasicAsyncEnumerable ( iterator ) ; } ;