@reactivex/ix-esnext-esm
Version:
The Interactive Extensions for JavaScript
35 lines (33 loc) • 1.22 kB
JavaScript
import { IterableX } from '../iterablex';
import { identity } from '../../util/identity';
import { comparer as defaultComparer } from '../../util/comparer';
export class DistinctUntilChangedIterable extends IterableX {
constructor(source, keySelector, comparer) {
super();
this._source = source;
this._keySelector = keySelector;
this._comparer = comparer;
}
*[Symbol.iterator]() {
let currentKey = {};
let hasCurrentKey = false;
for (const item of this._source) {
const key = this._keySelector(item);
let comparerEquals = false;
if (hasCurrentKey) {
comparerEquals = this._comparer(currentKey, key);
}
if (!hasCurrentKey || !comparerEquals) {
hasCurrentKey = true;
currentKey = key;
yield item;
}
}
}
}
export function distinctUntilChanged(keySelector = identity, comparer = defaultComparer) {
return function distinctUntilChangedOperatorFunction(source) {
return new DistinctUntilChangedIterable(source, keySelector, comparer);
};
}
//# sourceMappingURL=distinctuntilchanged.mjs.map