UNPKG

1.94 kBTypeScriptView Raw
1import { IIterator } from './iter';
2/**
3 * An object which can produce a reverse iterator over its values.
4 */
5export interface IRetroable<T> {
6 /**
7 * Get a reverse iterator over the object's values.
8 *
9 * @returns An iterator which yields the object's values in reverse.
10 */
11 retro(): IIterator<T>;
12}
13/**
14 * A type alias for a retroable or builtin array-like object.
15 */
16export declare type RetroableOrArrayLike<T> = IRetroable<T> | ArrayLike<T>;
17/**
18 * Create an iterator for a retroable object.
19 *
20 * @param object - The retroable or array-like object of interest.
21 *
22 * @returns An iterator which traverses the object's values in reverse.
23 *
24 * #### Example
25 * ```typescript
26 * import { retro, toArray } from '@phosphor/algorithm';
27 *
28 * let data = [1, 2, 3, 4, 5, 6];
29 *
30 * let stream = retro(data);
31 *
32 * toArray(stream); // [6, 5, 4, 3, 2, 1]
33 * ```
34 */
35export declare function retro<T>(object: RetroableOrArrayLike<T>): IIterator<T>;
36/**
37 * An iterator which traverses an array-like object in reverse.
38 *
39 * #### Notes
40 * This iterator can be used for any builtin JS array-like object.
41 */
42export declare class RetroArrayIterator<T> implements IIterator<T> {
43 /**
44 * Construct a new retro iterator.
45 *
46 * @param source - The array-like object of interest.
47 */
48 constructor(source: ArrayLike<T>);
49 /**
50 * Get an iterator over the object's values.
51 *
52 * @returns An iterator which yields the object's values.
53 */
54 iter(): IIterator<T>;
55 /**
56 * Create an independent clone of the iterator.
57 *
58 * @returns A new independent clone of the iterator.
59 */
60 clone(): IIterator<T>;
61 /**
62 * Get the next value from the iterator.
63 *
64 * @returns The next value from the iterator, or `undefined`.
65 */
66 next(): T | undefined;
67 private _index;
68 private _source;
69}