import { IterableX } from '../iterablex' ; import { MonoTypeOperatorFunction } from '../../interfaces' ; export class ExpandIterable < TSource > extends IterableX < TSource > { private _source : Iterable < TSource > ; private _fn : ( value : TSource ) => Iterable < TSource > ; constructor ( source , fn ) { super ( ) ; this . _source = source ; this . _fn = fn ; } * [ Symbol . iterator ] ( ) { const q = [ this . _source ] ; while ( q . length > 0 ) { const src = q . shift ( ) ; for ( const item of src ! ) { q . push ( this . _fn ( item ) ) ; yield item ; } } } } template TSource param { ( ( value : TSource ) => Iterable < TSource > ) } selector returns { MonoTypeOperatorFunction < TSource > } export function expand < TSource > ( selector ) { return function expandOperatorFunction ( source ) : IterableX < TSource > { return new ExpandIterable < TSource > ( source , selector ) ; } ; }