import { IEnumerable , IFlatten } from "../../types" ; import { BasicEnumerable } from "../BasicEnumerable" ; type FlattenFunc = { param source param shallow < TSource > ( source , shallow ? ) : IEnumerable < TSource > ; param source param shallow < TSource > ( source , shallow ) : IEnumerable < TSource | Iterable < TSource > > ; } ; export const flatten = < TSource > ( source , shallow ? ) : IEnumerable < TSource | Iterable < TSource > > => { function * iterator ( source ) { for ( const item of source ) { if ( item [ Symbol . iterator ] !== undefined && typeof item !== "string" ) { yield * shallow ? item : iterator ( item ) ; } else { yield item ; } } } return new BasicEnumerable ( ( ) => iterator ( source ) ) ; } ;