import { IAsyncEnumerable , IAsyncFlatten } from "../../types" ; import { BasicAsyncEnumerable } from "../BasicAsyncEnumerable" ; type FlattenAsyncFunc = { param source param shallow < TSource > ( source , shallow ? ) : IAsyncEnumerable < TSource > ; param source param shallow < TSource > ( source , shallow ) : IAsyncEnumerable < TSource | AsyncIterable < TSource > > ; } ; export const flattenAsync = < TSource > ( source , shallow ? ) : IAsyncEnumerable < TSource | AsyncIterable < TSource > > => { async function * iterator ( sourceInner ) { for await ( const item of sourceInner ) { if ( item [ Symbol . asyncIterator ] !== undefined ) { const items = shallow ? item : iterator ( item as AsyncIterable < any > ) ; for await ( const inner of items ) { yield inner ; } } else { yield item ; } } } return new BasicAsyncEnumerable ( ( ) => iterator ( source ) ) ; } ;