UNPKG

1.7 kBTypeScriptView Raw
1import { IIterator, IterableOrArrayLike } from './iter';
2/**
3 * Iterate over an iterable using a stepped increment.
4 *
5 * @param object - The iterable or array-like object of interest.
6 *
7 * @param step - The distance to step on each iteration. A value
8 * of less than `1` will behave the same as a value of `1`.
9 *
10 * @returns An iterator which traverses the iterable step-wise.
11 *
12 * #### Example
13 * ```typescript
14 * import { stride, toArray } from '@lumino/algorithm';
15 *
16 * let data = [1, 2, 3, 4, 5, 6];
17 *
18 * let stream = stride(data, 2);
19 *
20 * toArray(stream); // [1, 3, 5];
21 * ```
22 */
23export declare function stride<T>(object: IterableOrArrayLike<T>, step: number): IIterator<T>;
24/**
25 * An iterator which traverses a source iterator step-wise.
26 */
27export declare class StrideIterator<T> implements IIterator<T> {
28 /**
29 * Construct a new stride iterator.
30 *
31 * @param source - The iterator of values of interest.
32 *
33 * @param step - The distance to step on each iteration. A value
34 * of less than `1` will behave the same as a value of `1`.
35 */
36 constructor(source: IIterator<T>, step: number);
37 /**
38 * Get an iterator over the object's values.
39 *
40 * @returns An iterator which yields the object's values.
41 */
42 iter(): IIterator<T>;
43 /**
44 * Create an independent clone of the iterator.
45 *
46 * @returns A new independent clone of the iterator.
47 */
48 clone(): IIterator<T>;
49 /**
50 * Get the next value from the iterator.
51 *
52 * @returns The next value from the iterator, or `undefined`.
53 */
54 next(): T | undefined;
55 private _source;
56 private _step;
57}
58//# sourceMappingURL=stride.d.ts.map
\No newline at end of file