@reactivex/ix-esnext-esm
Version:
The Interactive Extensions for JavaScript
30 lines (28 loc) • 971 B
JavaScript
import { IterableX } from '../iterablex';
import { identity } from '../../util/identity';
import { arrayIndexOf } from '../../util/arrayindexof';
import { comparer as defaultComparer } from '../../util/comparer';
export class DistinctIterable extends IterableX {
constructor(source, keySelector, cmp) {
super();
this._source = source;
this._keySelector = keySelector;
this._cmp = cmp;
}
*[Symbol.iterator]() {
const set = [];
for (const item of this._source) {
const key = this._keySelector(item);
if (arrayIndexOf(set, key, this._cmp) === -1) {
set.push(key);
yield item;
}
}
}
}
export function distinct(keySelector = identity, comparer = defaultComparer) {
return function distinctOperatorFunction(source) {
return new DistinctIterable(source, keySelector, comparer);
};
}
//# sourceMappingURL=distinct.mjs.map