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