1 | /**
|
2 | * Find the first value in an iterable which matches a predicate.
|
3 | *
|
4 | * @param object - The iterable object to search.
|
5 | *
|
6 | * @param fn - The predicate function to apply to the values.
|
7 | *
|
8 | * @returns The first matching value, or `undefined` if no matching
|
9 | * value is found.
|
10 | *
|
11 | * #### Complexity
|
12 | * Linear.
|
13 | *
|
14 | * #### Example
|
15 | * ```typescript
|
16 | * import { find } from '@lumino/algorithm';
|
17 | *
|
18 | * interface IAnimal { species: string, name: string };
|
19 | *
|
20 | * function isCat(value: IAnimal): boolean {
|
21 | * return value.species === 'cat';
|
22 | * }
|
23 | *
|
24 | * let data: IAnimal[] = [
|
25 | * { species: 'dog', name: 'spot' },
|
26 | * { species: 'cat', name: 'fluffy' },
|
27 | * { species: 'alligator', name: 'pocho' }
|
28 | * ];
|
29 | *
|
30 | * find(data, isCat).name; // 'fluffy'
|
31 | * ```
|
32 | */
|
33 | export declare function find<T>(object: Iterable<T>, fn: (value: T, index: number) => boolean): T | undefined;
|
34 | /**
|
35 | * Find the index of the first value which matches a predicate.
|
36 | *
|
37 | * @param object - The iterable object to search.
|
38 | *
|
39 | * @param fn - The predicate function to apply to the values.
|
40 | *
|
41 | * @returns The index of the first matching value, or `-1` if no
|
42 | * matching value is found.
|
43 | *
|
44 | * #### Complexity
|
45 | * Linear.
|
46 | *
|
47 | * #### Example
|
48 | * ```typescript
|
49 | * import { findIndex } from '@lumino/algorithm';
|
50 | *
|
51 | * interface IAnimal { species: string, name: string };
|
52 | *
|
53 | * function isCat(value: IAnimal): boolean {
|
54 | * return value.species === 'cat';
|
55 | * }
|
56 | *
|
57 | * let data: IAnimal[] = [
|
58 | * { species: 'dog', name: 'spot' },
|
59 | * { species: 'cat', name: 'fluffy' },
|
60 | * { species: 'alligator', name: 'pocho' }
|
61 | * ];
|
62 | *
|
63 | * findIndex(data, isCat); // 1
|
64 | * ```
|
65 | */
|
66 | export declare function findIndex<T>(object: Iterable<T>, fn: (value: T, index: number) => boolean): number;
|
67 | /**
|
68 | * Find the minimum value in an iterable.
|
69 | *
|
70 | * @param object - The iterable object to search.
|
71 | *
|
72 | * @param fn - The 3-way comparison function to apply to the values.
|
73 | * It should return `< 0` if the first value is less than the second.
|
74 | * `0` if the values are equivalent, or `> 0` if the first value is
|
75 | * greater than the second.
|
76 | *
|
77 | * @returns The minimum value in the iterable. If multiple values are
|
78 | * equivalent to the minimum, the left-most value is returned. If
|
79 | * the iterable is empty, this returns `undefined`.
|
80 | *
|
81 | * #### Complexity
|
82 | * Linear.
|
83 | *
|
84 | * #### Example
|
85 | * ```typescript
|
86 | * import { min } from '@lumino/algorithm';
|
87 | *
|
88 | * function numberCmp(a: number, b: number): number {
|
89 | * return a - b;
|
90 | * }
|
91 | *
|
92 | * min([7, 4, 0, 3, 9, 4], numberCmp); // 0
|
93 | * ```
|
94 | */
|
95 | export declare function min<T>(object: Iterable<T>, fn: (first: T, second: T) => number): T | undefined;
|
96 | /**
|
97 | * Find the maximum value in an iterable.
|
98 | *
|
99 | * @param object - The iterable object to search.
|
100 | *
|
101 | * @param fn - The 3-way comparison function to apply to the values.
|
102 | * It should return `< 0` if the first value is less than the second.
|
103 | * `0` if the values are equivalent, or `> 0` if the first value is
|
104 | * greater than the second.
|
105 | *
|
106 | * @returns The maximum value in the iterable. If multiple values are
|
107 | * equivalent to the maximum, the left-most value is returned. If
|
108 | * the iterable is empty, this returns `undefined`.
|
109 | *
|
110 | * #### Complexity
|
111 | * Linear.
|
112 | *
|
113 | * #### Example
|
114 | * ```typescript
|
115 | * import { max } from '@lumino/algorithm';
|
116 | *
|
117 | * function numberCmp(a: number, b: number): number {
|
118 | * return a - b;
|
119 | * }
|
120 | *
|
121 | * max([7, 4, 0, 3, 9, 4], numberCmp); // 9
|
122 | * ```
|
123 | */
|
124 | export declare function max<T>(object: Iterable<T>, fn: (first: T, second: T) => number): T | undefined;
|
125 | /**
|
126 | * Find the minimum and maximum values in an iterable.
|
127 | *
|
128 | * @param object - The iterable object to search.
|
129 | *
|
130 | * @param fn - The 3-way comparison function to apply to the values.
|
131 | * It should return `< 0` if the first value is less than the second.
|
132 | * `0` if the values are equivalent, or `> 0` if the first value is
|
133 | * greater than the second.
|
134 | *
|
135 | * @returns A 2-tuple of the `[min, max]` values in the iterable. If
|
136 | * multiple values are equivalent, the left-most values are returned.
|
137 | * If the iterable is empty, this returns `undefined`.
|
138 | *
|
139 | * #### Complexity
|
140 | * Linear.
|
141 | *
|
142 | * #### Example
|
143 | * ```typescript
|
144 | * import { minmax } from '@lumino/algorithm';
|
145 | *
|
146 | * function numberCmp(a: number, b: number): number {
|
147 | * return a - b;
|
148 | * }
|
149 | *
|
150 | * minmax([7, 4, 0, 3, 9, 4], numberCmp); // [0, 9]
|
151 | * ```
|
152 | */
|
153 | export declare function minmax<T>(object: Iterable<T>, fn: (first: T, second: T) => number): [T, T] | undefined;
|