UNPKG

@reactivex/ix-esnext-esm

Version:

The Interactive Extensions for JavaScript

38 lines (36 loc) 1.18 kB
import { AsyncIterableX } from '../asynciterablex'; import { arrayIndexOfAsync } from '../../util/arrayindexof'; import { comparerAsync } from '../../util/comparer'; async function arrayRemove(array, item, comparer) { const idx = await arrayIndexOfAsync(array, item, comparer); if (idx === -1) { return false; } array.splice(idx, 1); return true; } export class IntersectAsyncIterable extends AsyncIterableX { constructor(first, second, comparer) { super(); this._first = first; this._second = second; this._comparer = comparer; } async *[Symbol.asyncIterator]() { const map = []; for await (const secondItem of this._second) { map.push(secondItem); } for await (const firstItem of this._first) { if (await arrayRemove(map, firstItem, this._comparer)) { yield firstItem; } } } } export function intersect(second, comparer = comparerAsync) { return function intersectOperatorFunction(first) { return new IntersectAsyncIterable(first, second, comparer); }; } //# sourceMappingURL=intersect.mjs.map