@reactivex/ix-es5-esm
Version:
The Interactive Extensions for JavaScript
73 lines (71 loc) • 3.18 kB
JavaScript
import { __asyncGenerator, __await, __extends, __generator } from "tslib";
import { AsyncIterableX } from '../asynciterablex.js';
import { toArray } from '../toarray.js';
import { throwIfAborted } from '../../aborterror.js';
/** @ignore */
var ScanRightAsyncIterable = /** @class */ (function (_super) {
__extends(ScanRightAsyncIterable, _super);
function ScanRightAsyncIterable(source, options) {
var _this = _super.call(this) || this;
_this._source = source;
_this._fn = options['callback'];
_this._hasSeed = options.hasOwnProperty('seed');
_this._seed = options['seed'];
return _this;
}
ScanRightAsyncIterable.prototype[Symbol.asyncIterator] = function (signal) {
return __asyncGenerator(this, arguments, function _a() {
var hasValue, acc, source, offset, item;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
throwIfAborted(signal);
hasValue = false;
acc = this._seed;
return [4 /*yield*/, __await(toArray(this._source, signal))];
case 1:
source = _b.sent();
offset = source.length - 1;
_b.label = 2;
case 2:
if (!(offset >= 0)) return [3 /*break*/, 8];
item = source[offset];
if (!(hasValue || (hasValue = this._hasSeed))) return [3 /*break*/, 6];
return [4 /*yield*/, __await(this._fn(acc, item, offset, signal))];
case 3:
acc = _b.sent();
return [4 /*yield*/, __await(acc)];
case 4: return [4 /*yield*/, _b.sent()];
case 5:
_b.sent();
return [3 /*break*/, 7];
case 6:
acc = item;
hasValue = true;
_b.label = 7;
case 7:
offset--;
return [3 /*break*/, 2];
case 8: return [2 /*return*/];
}
});
});
};
return ScanRightAsyncIterable;
}(AsyncIterableX));
export { 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.
*/
export function scanRight(options) {
return function scanRightOperatorFunction(source) {
return new ScanRightAsyncIterable(source, options);
};
}
//# sourceMappingURL=scanright.js.map