@reactivex/ix-esnext-esm
Version:
The Interactive Extensions for JavaScript
30 lines (28 loc) • 768 B
JavaScript
import { IterableX } from '../iterablex';
export class TakeLastIterable extends IterableX {
constructor(source, count) {
super();
this._source = source;
this._count = count;
}
*[Symbol.iterator]() {
if (this._count > 0) {
const q = [];
for (const item of this._source) {
if (q.length >= this._count) {
q.shift();
}
q.push(item);
}
while (q.length > 0) {
yield q.shift();
}
}
}
}
export function takeLast(count) {
return function takeLastOperatorFunction(source) {
return new TakeLastIterable(source, count);
};
}
//# sourceMappingURL=takelast.mjs.map