import { AsyncIterableX } from '../asynciterablex' ; import { arrayIndexOfAsync } from '../../util/arrayindexof' ; import { comparerAsync } from '../../util/comparer' ; import { MonoTypeOperatorAsyncFunction } from '../../interfaces' ; import { wrapWithAbort } from './withabort' ; import { throwIfAborted } from '../../aborterror' ; export class ExceptAsyncIterable < TSource > extends AsyncIterableX < TSource > { private _first : AsyncIterable < TSource > ; private _second : AsyncIterable < TSource > ; private _comparer : ( x : TSource , y : TSource ) => boolean | Promise < boolean > ; constructor ( first , second , comparer ) { super ( ) ; this . _first = first ; this . _second = second ; this . _comparer = comparer ; } async * [ Symbol . asyncIterator ] ( signal ? ) { throwIfAborted ( signal ) ; const map = [ ] as TSource [ ] ; for await ( const secondItem of wrapWithAbort ( this . _second , signal ) ) { map . push ( secondItem ) ; } for await ( const firstItem of wrapWithAbort ( this . _first , signal ) ) { if ( ( await arrayIndexOfAsync ( map , firstItem , this . _comparer ) ) === - 1 ) { map . push ( firstItem ) ; yield firstItem ; } } } } template TSource param { AsyncIterable < TSource > } second param { ( ( x : TSource , y : TSource ) => boolean | Promise < boolean > ) } comparer returns { MonoTypeOperatorAsyncFunction < TSource > } export function except < TSource > ( second , comparer = comparerAsync ) { return function exceptOperatorFunction ( first ) : AsyncIterableX < TSource > { return new ExceptAsyncIterable < TSource > ( first , second , comparer ) ; } ; }