UNPKG

@reactivex/ix-es5-esm

Version:

The Interactive Extensions for JavaScript

86 lines (84 loc) 3.65 kB
import { __asyncGenerator, __asyncValues, __await, __extends, __generator } from "tslib"; import { AsyncIterableX } from '../asynciterablex.js'; import { wrapWithAbort } from './withabort.js'; import { throwIfAborted } from '../../aborterror.js'; /** @ignore */ var PairwiseAsyncIterable = /** @class */ (function (_super) { __extends(PairwiseAsyncIterable, _super); function PairwiseAsyncIterable(source) { var _this = _super.call(this) || this; _this._source = source; return _this; } PairwiseAsyncIterable.prototype[Symbol.asyncIterator] = function (signal) { return __asyncGenerator(this, arguments, function _a() { var value, hasValue, _b, _c, _d, item, e_1_1; var _e, e_1, _f, _g; return __generator(this, function (_h) { switch (_h.label) { case 0: throwIfAborted(signal); hasValue = false; _h.label = 1; case 1: _h.trys.push([1, 10, 11, 16]); _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*/, 9]; _g = _d.value; _b = false; item = _g; if (!!hasValue) return [3 /*break*/, 4]; hasValue = true; return [3 /*break*/, 7]; case 4: return [4 /*yield*/, __await([value, item])]; case 5: return [4 /*yield*/, _h.sent()]; case 6: _h.sent(); _h.label = 7; case 7: value = item; _h.label = 8; case 8: _b = true; return [3 /*break*/, 2]; case 9: return [3 /*break*/, 16]; case 10: e_1_1 = _h.sent(); e_1 = { error: e_1_1 }; return [3 /*break*/, 16]; case 11: _h.trys.push([11, , 14, 15]); if (!(!_b && !_e && (_f = _c.return))) return [3 /*break*/, 13]; return [4 /*yield*/, __await(_f.call(_c))]; case 12: _h.sent(); _h.label = 13; case 13: return [3 /*break*/, 15]; case 14: if (e_1) throw e_1.error; return [7 /*endfinally*/]; case 15: return [7 /*endfinally*/]; case 16: return [2 /*return*/]; } }); }); }; return PairwiseAsyncIterable; }(AsyncIterableX)); export { PairwiseAsyncIterable }; /** * Returns a sequence of each element in the input sequence and its predecessor, with the exception of the * first element which is only returned as the predecessor of the second element. * * @template TSource The type of the elements in the source sequence. * @returns {OperatorAsyncFunction<TSource, TSource[]>} The result sequence. */ export function pairwise() { return function pairwiseOperatorFunction(source) { return new PairwiseAsyncIterable(source); }; } //# sourceMappingURL=pairwise.js.map