import { IParallelEnumerable , IParallelFlatten , ParallelGeneratorType } from "../../types" ; import { BasicParallelEnumerable } from "../BasicParallelEnumerable" ; type FlatternParallelFunc = { param source param shallow < TSource > ( source , shallow ? ) : IParallelEnumerable < TSource > ; param source param shallow < TSource > ( source , shallow ) : IParallelEnumerable < TSource | AsyncIterable < TSource > > ; } ; export const flattenParallel = < TSource > ( source , shallow ? ) : IParallelEnumerable < 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 ; } } } const generator = async ( ) => { const results = [ ] ; for await ( const x of iterator ( source ) ) { results . push ( x ) ; } return results ; } ; return new BasicParallelEnumerable ( { generator , type : ParallelGeneratorType . PromiseToArray , } ) ; } ;