UNPKG

ix

Version:

The Interactive Extensions for JavaScript

55 lines (53 loc) 2.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.scanRight = exports.ScanRightAsyncIterable = void 0; const tslib_1 = require("tslib"); const asynciterablex_js_1 = require("../asynciterablex.js"); const toarray_js_1 = require("../toarray.js"); const aborterror_js_1 = require("../../aborterror.js"); /** @ignore */ class ScanRightAsyncIterable extends asynciterablex_js_1.AsyncIterableX { constructor(source, options) { super(); this._source = source; this._fn = options['callback']; this._hasSeed = options.hasOwnProperty('seed'); this._seed = options['seed']; } [Symbol.asyncIterator](signal) { return tslib_1.__asyncGenerator(this, arguments, function* _a() { (0, aborterror_js_1.throwIfAborted)(signal); let hasValue = false; let acc = this._seed; const source = yield tslib_1.__await((0, toarray_js_1.toArray)(this._source, signal)); for (let offset = source.length - 1; offset >= 0; offset--) { const item = source[offset]; if (hasValue || (hasValue = this._hasSeed)) { acc = yield tslib_1.__await(this._fn(acc, item, offset, signal)); yield yield tslib_1.__await(acc); } else { acc = item; hasValue = true; } } }); } } exports.ScanRightAsyncIterable = ScanRightAsyncIterable; /** * Applies an accumulator function over an async-iterable sequence from the right and returns each intermediate result. * The specified seed value, if given, is used as the initial accumulator value. * * @template T The type of the elements in the source sequence. * @template R The type of the result of the aggregation. * @param {ScanOptions<T, R>} options The options including the accumulator function and seed. * @returns {OperatorAsyncFunction<T, R>} An async-enumerable sequence containing the accumulated values from the right. */ function scanRight(options) { return function scanRightOperatorFunction(source) { return new ScanRightAsyncIterable(source, options); }; } exports.scanRight = scanRight; //# sourceMappingURL=scanright.js.map