@reactivex/ix-esnext-esm
Version:
The Interactive Extensions for JavaScript
38 lines (36 loc) • 1.12 kB
JavaScript
import { IterableX } from '../iterablex';
import { arrayIndexOf } from '../../util/arrayindexof';
import { comparer as defaultComparer } from '../../util/comparer';
function arrayRemove(array, item, comparer) {
const idx = arrayIndexOf(array, item, comparer);
if (idx === -1) {
return false;
}
array.splice(idx, 1);
return true;
}
export class IntersectIterable extends IterableX {
constructor(first, second, comparer) {
super();
this._first = first;
this._second = second;
this._comparer = comparer;
}
*[Symbol.iterator]() {
const map = [];
for (const secondItem of this._second) {
map.push(secondItem);
}
for (const firstItem of this._first) {
if (arrayRemove(map, firstItem, this._comparer)) {
yield firstItem;
}
}
}
}
export function intersect(second, comparer = defaultComparer) {
return function intersectOperatorFunction(first) {
return new IntersectIterable(first, second, comparer);
};
}
//# sourceMappingURL=intersect.mjs.map