@reactivex/ix-esnext-esm
Version:
The Interactive Extensions for JavaScript
35 lines (33 loc) • 1.04 kB
JavaScript
import { IterableX } from '../iterablex';
import { toArray } from '../toarray';
export class ScanRightIterable extends IterableX {
constructor(source, fn, seed) {
super();
this._source = source;
this._fn = fn;
this._hasSeed = seed.length === 1;
this._seed = seed[0];
}
*[Symbol.iterator]() {
let hasValue = false;
let acc = this._seed;
const source = toArray(this._source);
for (let offset = source.length - 1; offset >= 0; offset--) {
const item = source[offset];
if (hasValue || (hasValue = this._hasSeed)) {
acc = this._fn(acc, item, offset);
yield acc;
}
else {
acc = item;
hasValue = true;
}
}
}
}
export function scanRight(accumulator, ...seed) {
return function scanRightOperatorFunction(source) {
return new ScanRightIterable(source, accumulator, seed);
};
}
//# sourceMappingURL=scanright.mjs.map