UNPKG

2.96 kBTypeScriptView Raw
1/**
2 * Create an array from an iterable of values.
3 *
4 * @deprecated
5 *
6 * @param object - The iterable object of interest.
7 *
8 * @returns A new array of values from the given object.
9 *
10 * #### Example
11 * ```typescript
12 * import { toArray } from '@lumino/algorithm';
13 *
14 * let stream = [1, 2, 3, 4, 5, 6][Symbol.iterator]();
15 *
16 * toArray(stream); // [1, 2, 3, 4, 5, 6];
17 * ```
18 */
19export declare function toArray<T>(object: Iterable<T>): T[];
20/**
21 * Create an object from an iterable of key/value pairs.
22 *
23 * @param object - The iterable object of interest.
24 *
25 * @returns A new object mapping keys to values.
26 *
27 * #### Example
28 * ```typescript
29 * import { toObject } from '@lumino/algorithm';
30 *
31 * let data: [string, number][] = [['one', 1], ['two', 2], ['three', 3]];
32 *
33 * toObject(data); // { one: 1, two: 2, three: 3 }
34 * ```
35 */
36export declare function toObject<T>(object: Iterable<[string, T]>): {
37 [key: string]: T;
38};
39/**
40 * Invoke a function for each value in an iterable.
41 *
42 * @deprecated
43 *
44 * @param object - The iterable object of interest.
45 *
46 * @param fn - The callback function to invoke for each value.
47 *
48 * #### Notes
49 * Iteration can be terminated early by returning `false` from the
50 * callback function.
51 *
52 * #### Complexity
53 * Linear.
54 *
55 * #### Example
56 * ```typescript
57 * import { each } from '@lumino/algorithm';
58 *
59 * let data = [5, 7, 0, -2, 9];
60 *
61 * each(data, value => { console.log(value); });
62 * ```
63 */
64export declare function each<T>(object: Iterable<T>, fn: (value: T, index: number) => boolean | void): void;
65/**
66 * Test whether all values in an iterable satisfy a predicate.
67 *
68 * @param object - The iterable object of interest.
69 *
70 * @param fn - The predicate function to invoke for each value.
71 *
72 * @returns `true` if all values pass the test, `false` otherwise.
73 *
74 * #### Notes
75 * Iteration terminates on the first `false` predicate result.
76 *
77 * #### Complexity
78 * Linear.
79 *
80 * #### Example
81 * ```typescript
82 * import { every } from '@lumino/algorithm';
83 *
84 * let data = [5, 7, 1];
85 *
86 * every(data, value => value % 2 === 0); // false
87 * every(data, value => value % 2 === 1); // true
88 * ```
89 */
90export declare function every<T>(object: Iterable<T>, fn: (value: T, index: number) => boolean): boolean;
91/**
92 * Test whether any value in an iterable satisfies a predicate.
93 *
94 * @param object - The iterable object of interest.
95 *
96 * @param fn - The predicate function to invoke for each value.
97 *
98 * @returns `true` if any value passes the test, `false` otherwise.
99 *
100 * #### Notes
101 * Iteration terminates on the first `true` predicate result.
102 *
103 * #### Complexity
104 * Linear.
105 *
106 * #### Example
107 * ```typescript
108 * import { some } from '@lumino/algorithm';
109 *
110 * let data = [5, 7, 1];
111 *
112 * some(data, value => value === 7); // true
113 * some(data, value => value === 3); // false
114 * ```
115 */
116export declare function some<T>(object: Iterable<T>, fn: (value: T, index: number) => boolean): boolean;