import { IterableX } from '../iterablex' ; import { OperatorFunction } from '../../interfaces' ; export class FlatMapIterable < TSource , TResult > extends IterableX < TResult > { private _source : Iterable < TSource > ; private _fn : ( value : TSource , index : number ) => Iterable < TResult > ; private _thisArg ? : any ; constructor ( source , fn , thisArg ? ) { super ( ) ; this . _source = source ; this . _fn = fn ; this . _thisArg = thisArg ; } * [ Symbol . iterator ] ( ) { let index = 0 ; for ( const outerItem of this . _source ) { for ( const innerItem of this . _fn . call ( this . _thisArg , outerItem , index ++ ) ) { yield innerItem ; } } } } template TSource template TResult param { ( ( value : TSource , index : number ) => Iterable < TResult > ) } selector param { * } thisArg returns { OperatorFunction < TSource , TResult > } export function flatMap < TSource , TResult > ( selector , thisArg ? ) { return function flatMapOperatorFunction ( source ) : IterableX < TResult > { return new FlatMapIterable < TSource , TResult > ( source , selector , thisArg ) ; } ; }