UNPKG

@reactivex/ix-esnext-esm

Version:

The Interactive Extensions for JavaScript

30 lines (28 loc) 810 B
import { AsyncIterableX } from '../asynciterablex'; export class TakeLastAsyncIterable extends AsyncIterableX { constructor(source, count) { super(); this._source = source; this._count = count; } async *[Symbol.asyncIterator]() { if (this._count > 0) { const q = []; for await (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 TakeLastAsyncIterable(source, count); }; } //# sourceMappingURL=takelast.mjs.map