@reactivex/ix-es5-esm
Version:
The Interactive Extensions for JavaScript
80 lines (78 loc) • 3.59 kB
JavaScript
import { __extends, __generator, __values } from "tslib";
import { IterableX } from '../iterablex.js';
import { identity } from '../../util/identity.js';
import { comparer as defaultComparer } from '../../util/comparer.js';
/** @ignore */
var DistinctUntilChangedIterable = /** @class */ (function (_super) {
__extends(DistinctUntilChangedIterable, _super);
function DistinctUntilChangedIterable(source, keySelector, comparer) {
var _this = _super.call(this) || this;
_this._source = source;
_this._keySelector = keySelector;
_this._comparer = comparer;
return _this;
}
DistinctUntilChangedIterable.prototype[Symbol.iterator] = function () {
var currentKey, hasCurrentKey, _a, _b, item, key, comparerEquals, e_1_1;
var e_1, _c;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
currentKey = {};
hasCurrentKey = false;
_d.label = 1;
case 1:
_d.trys.push([1, 6, 7, 8]);
_a = __values(this._source), _b = _a.next();
_d.label = 2;
case 2:
if (!!_b.done) return [3 /*break*/, 5];
item = _b.value;
key = this._keySelector(item);
comparerEquals = false;
if (hasCurrentKey) {
comparerEquals = this._comparer(currentKey, key);
}
if (!(!hasCurrentKey || !comparerEquals)) return [3 /*break*/, 4];
hasCurrentKey = true;
currentKey = key;
return [4 /*yield*/, item];
case 3:
_d.sent();
_d.label = 4;
case 4:
_b = _a.next();
return [3 /*break*/, 2];
case 5: return [3 /*break*/, 8];
case 6:
e_1_1 = _d.sent();
e_1 = { error: e_1_1 };
return [3 /*break*/, 8];
case 7:
try {
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
}
finally { if (e_1) throw e_1.error; }
return [7 /*endfinally*/];
case 8: return [2 /*return*/];
}
});
};
return DistinctUntilChangedIterable;
}(IterableX));
export { DistinctUntilChangedIterable };
/**
* Returns an async-iterable sequence that contains only distinct contiguous elements according to the optional keySelector and comparer.
*
* @template TSource The type of the elements in the source sequence.
* @template TKey The type of the discriminator key computed for each element in the source sequence.
* @param {DistinctOptions<TSource, TKey = TSource>} [options] The optional options for adding a key selector and comparer.
* @returns {MonoTypeOperatorFunction<TSource>} An operator that returns an async-iterable that contains only distinct contiguous items.
*/
export function distinctUntilChanged(options) {
return function distinctUntilChangedOperatorFunction(source) {
var _a = options || {}, _b = _a["keySelector"], keySelector = _b === void 0 ? identity : _b, _c = _a["comparer"], comparer = _c === void 0 ? defaultComparer : _c;
return new DistinctUntilChangedIterable(source, keySelector, comparer);
};
}
//# sourceMappingURL=distinctuntilchanged.js.map