UNPKG

@reactivex/ix-es5-esm

Version:

The Interactive Extensions for JavaScript

99 lines (97 loc) 4.88 kB
import { __asyncGenerator, __asyncValues, __await, __extends, __generator } from "tslib"; import { AsyncIterableX } from '../asynciterablex.js'; import { identityAsync } from '../../util/identity.js'; import { comparerAsync } from '../../util/comparer.js'; import { wrapWithAbort } from './withabort.js'; import { throwIfAborted } from '../../aborterror.js'; /** @ignore */ var DistinctUntilChangedAsyncIterable = /** @class */ (function (_super) { __extends(DistinctUntilChangedAsyncIterable, _super); function DistinctUntilChangedAsyncIterable(source, keySelector, comparer) { var _this = _super.call(this) || this; _this._source = source; _this._keySelector = keySelector; _this._comparer = comparer; return _this; } DistinctUntilChangedAsyncIterable.prototype[Symbol.asyncIterator] = function (signal) { return __asyncGenerator(this, arguments, function _a() { var currentKey, hasCurrentKey, _b, _c, _d, item, key, comparerEquals, e_1_1; var _e, e_1, _f, _g; return __generator(this, function (_h) { switch (_h.label) { case 0: throwIfAborted(signal); hasCurrentKey = false; _h.label = 1; case 1: _h.trys.push([1, 11, 12, 17]); _b = true, _c = __asyncValues(wrapWithAbort(this._source, signal)); _h.label = 2; case 2: return [4 /*yield*/, __await(_c.next())]; case 3: if (!(_d = _h.sent(), _e = _d.done, !_e)) return [3 /*break*/, 10]; _g = _d.value; _b = false; item = _g; return [4 /*yield*/, __await(this._keySelector(item, signal))]; case 4: key = _h.sent(); comparerEquals = false; if (!hasCurrentKey) return [3 /*break*/, 6]; return [4 /*yield*/, __await(this._comparer(currentKey, key))]; case 5: comparerEquals = _h.sent(); _h.label = 6; case 6: if (!(!hasCurrentKey || !comparerEquals)) return [3 /*break*/, 9]; hasCurrentKey = true; currentKey = key; return [4 /*yield*/, __await(item)]; case 7: return [4 /*yield*/, _h.sent()]; case 8: _h.sent(); _h.label = 9; case 9: _b = true; return [3 /*break*/, 2]; case 10: return [3 /*break*/, 17]; case 11: e_1_1 = _h.sent(); e_1 = { error: e_1_1 }; return [3 /*break*/, 17]; case 12: _h.trys.push([12, , 15, 16]); if (!(!_b && !_e && (_f = _c.return))) return [3 /*break*/, 14]; return [4 /*yield*/, __await(_f.call(_c))]; case 13: _h.sent(); _h.label = 14; case 14: return [3 /*break*/, 16]; case 15: if (e_1) throw e_1.error; return [7 /*endfinally*/]; case 16: return [7 /*endfinally*/]; case 17: return [2 /*return*/]; } }); }); }; return DistinctUntilChangedAsyncIterable; }(AsyncIterableX)); export { DistinctUntilChangedAsyncIterable }; /** * 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 {MonoTypeOperatorAsyncFunction<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 ? identityAsync : _b, _c = _a["comparer"], comparer = _c === void 0 ? comparerAsync : _c; return new DistinctUntilChangedAsyncIterable(source, keySelector, comparer); }; } //# sourceMappingURL=distinctuntilchanged.js.map