UNPKG

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