import { IterableX } from '../iterablex' ; import { arrayIndexOf } from '../../util/arrayindexof' ; import { comparer as defaultComparer } from '../../util/comparer' ; import { MonoTypeOperatorFunction } from '../../interfaces' ; export class UnionIterable < TSource > extends IterableX < TSource > { private _left : Iterable < TSource > ; private _right : Iterable < TSource > ; private _comparer : ( x : TSource , y : TSource ) => boolean ; constructor ( left , right , comparer ) { super ( ) ; this . _left = left ; this . _right = right ; this . _comparer = comparer ; } * [ Symbol . iterator ] ( ) { const map = [ ] as TSource [ ] ; for ( const lItem of this . _left ) { if ( arrayIndexOf ( map , lItem , this . _comparer ) === - 1 ) { map . push ( lItem ) ; yield lItem ; } } for ( const rItem of this . _right ) { if ( arrayIndexOf ( map , rItem , this . _comparer ) === - 1 ) { map . push ( rItem ) ; yield rItem ; } } } } template TSource param { AsyncIterable < TSource > } right param { ( ( x : TSource , y : TSource ) => boolean ) } comparer returns { MonoTypeOperatorFunction < TSource > } export function union < TSource > ( right , comparer = defaultComparer ) { return function unionOperatorFunction ( left ) : IterableX < TSource > { return new UnionIterable < TSource > ( left , right , comparer ) ; } ; }