import { IterableX } from '../iterablex.js'; import { MonoTypeOperatorFunction } from '../../interfaces.js'; /** @ignore */ export class ReverseIterable extends IterableX { private _source: Iterable; constructor(source: Iterable) { super(); this._source = source; } *[Symbol.iterator]() { const results = [] as TSource[]; for (const item of this._source) { results.unshift(item); } yield* results; } } /** * Reverses the iterable instance. * * @template TSource The type of the elements in the source sequence. * @returns {MonoTypeOperatorAsyncFunction} The iterable in reversed sequence. */ export function reverse(): MonoTypeOperatorFunction { return function reverseOperatorFunction(source: Iterable): IterableX { return new ReverseIterable(source); }; }