import { IterableX } from '../iterablex.js'; import { MonoTypeOperatorFunction } from '../../interfaces.js'; /** @ignore */ export class SkipLastIterable extends IterableX { private _source: Iterable; private _count: number; constructor(source: Iterable, count: number) { super(); this._source = source; this._count = count; } *[Symbol.iterator]() { const q = [] as TSource[]; for (const item of this._source) { q.push(item); if (q.length > this._count) { yield q.shift()!; } } } } /** * Bypasses a specified number of elements at the end of an iterable sequence. * * @template TSource The type of the elements in the source sequence. * @param {number} count Number of elements to bypass at the end of the source sequence. * @returns {MonoTypeOperatorFunction} An iterable sequence containing the * source sequence elements except for the bypassed ones at the end. */ export function skipLast(count: number): MonoTypeOperatorFunction { return function skipLastOperatorFunction(source: Iterable): IterableX { return new SkipLastIterable(source, count); }; }