@noldova/context.collections 0.0.9 → 0.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -14
- package/api/index.d.ts +1479 -0
- package/api/index.js +17 -0
- package/api/index.js.map +1 -1
- package/extensions/enumerable.extensions.js +36 -0
- package/extensions/enumerable.extensions.js.map +1 -0
- package/interfaces/i-equality-comparer.js +9 -0
- package/interfaces/i-equality-comparer.js.map +1 -0
- package/interfaces/i-read-only-dictionary.js +9 -0
- package/interfaces/i-read-only-dictionary.js.map +1 -0
- package/interfaces/i-read-only-list.js +9 -0
- package/interfaces/i-read-only-list.js.map +1 -0
- package/interfaces/i-read-only-set.js +9 -0
- package/interfaces/i-read-only-set.js.map +1 -0
- package/models/change-counter.js +23 -0
- package/models/change-counter.js.map +1 -0
- package/models/default-equality-comparer.js +35 -0
- package/models/default-equality-comparer.js.map +1 -0
- package/models/dictionary.js +74 -0
- package/models/dictionary.js.map +1 -0
- package/models/enumerable.js +399 -0
- package/models/enumerable.js.map +1 -0
- package/models/grouping.js +21 -0
- package/models/grouping.js.map +1 -0
- package/models/hash-set.js +87 -0
- package/models/hash-set.js.map +1 -0
- package/models/hash-table.js +122 -0
- package/models/hash-table.js.map +1 -0
- package/models/key-equality-comparer.js +22 -0
- package/models/key-equality-comparer.js.map +1 -0
- package/models/key-value-pair.js +16 -0
- package/models/key-value-pair.js.map +1 -0
- package/models/list.js +121 -0
- package/models/list.js.map +1 -0
- package/models/ordered-enumerable.js +35 -0
- package/models/ordered-enumerable.js.map +1 -0
- package/models/queue.js +80 -0
- package/models/queue.js.map +1 -0
- package/models/read-only-dictionary.js +37 -0
- package/models/read-only-dictionary.js.map +1 -0
- package/models/read-only-list.js +31 -0
- package/models/read-only-list.js.map +1 -0
- package/models/read-only-set.js +37 -0
- package/models/read-only-set.js.map +1 -0
- package/models/sort-entry.js +16 -0
- package/models/sort-entry.js.map +1 -0
- package/models/stack.js +57 -0
- package/models/stack.js.map +1 -0
- package/package.json +6 -2
- package/resources.js +26 -0
- package/resources.js.map +1 -0
- package/services/binary-search.service.js +5 -3
- package/services/binary-search.service.js.map +1 -1
- package/services/comparer.js +48 -0
- package/services/comparer.js.map +1 -0
- package/services/equality-comparers.js +16 -0
- package/services/equality-comparers.js.map +1 -0
- package/types/comparison.js +9 -0
- package/types/comparison.js.map +1 -0
package/api/index.d.ts
CHANGED
|
@@ -38,3 +38,1482 @@ export declare class BinarySearchService {
|
|
|
38
38
|
*/
|
|
39
39
|
public static floorIndex(values: readonly number[], target: number): number;
|
|
40
40
|
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Orders two values: a negative number when `left` comes first, zero when they
|
|
44
|
+
* are equal in this order, a positive number when `right` comes first. Any
|
|
45
|
+
* function of this shape also serves `Array.prototype.sort`.
|
|
46
|
+
*
|
|
47
|
+
* @template T The type of the values ordered.
|
|
48
|
+
*/
|
|
49
|
+
export declare type Comparison<T> = (left: T, right: T) => number;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Decides which keys are the same for a {@link Dictionary}, a {@link HashSet}
|
|
53
|
+
* and the query operators that match keys, such as `distinct`, `groupBy`,
|
|
54
|
+
* `join` and `union`.
|
|
55
|
+
*
|
|
56
|
+
* @template T The type of the values compared.
|
|
57
|
+
*
|
|
58
|
+
* @remarks
|
|
59
|
+
* `equals` must be reflexive, symmetric and transitive, and values it calls
|
|
60
|
+
* equal must return the same `hash`. Unequal values may share a hash; fewer
|
|
61
|
+
* shared hashes make lookups faster. Neither method may change while the value
|
|
62
|
+
* is a key in a collection.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* import { Dictionary, type IEqualityComparer } from "@noldova/context.collections";
|
|
67
|
+
*
|
|
68
|
+
* class IgnoringCase implements IEqualityComparer<string> {
|
|
69
|
+
* public equals(left: string, right: string): boolean {
|
|
70
|
+
* return left.toLowerCase() === right.toLowerCase();
|
|
71
|
+
* }
|
|
72
|
+
*
|
|
73
|
+
* public hash(value: string): number {
|
|
74
|
+
* return value.toLowerCase().length;
|
|
75
|
+
* }
|
|
76
|
+
* }
|
|
77
|
+
*
|
|
78
|
+
* const users = new Dictionary<string, number>([], new IgnoringCase());
|
|
79
|
+
* users.set("Leo", 1);
|
|
80
|
+
* users.get("LEO"); // 1
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export declare interface IEqualityComparer<T> {
|
|
84
|
+
/**
|
|
85
|
+
* Tells whether two values are the same key.
|
|
86
|
+
*/
|
|
87
|
+
equals(left: T, right: T): boolean;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Returns a number that is the same for every pair of values `equals` calls equal.
|
|
91
|
+
*/
|
|
92
|
+
hash(value: T): number;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* SameValueZero, the equality `Map` and `Set` use, with a hash for any
|
|
97
|
+
* value; {@link EqualityComparers.default} is one.
|
|
98
|
+
*
|
|
99
|
+
* @remarks
|
|
100
|
+
* Primitives are equal by value, with `NaN` equal to `NaN` and `-0` equal to
|
|
101
|
+
* `0`, and objects and functions by reference. The hash reads a primitive's
|
|
102
|
+
* text and numbers each object the first time this comparer hashes it, holding
|
|
103
|
+
* no reference that keeps the object alive; another comparer numbers objects
|
|
104
|
+
* on its own.
|
|
105
|
+
*/
|
|
106
|
+
export declare class DefaultEqualityComparer implements IEqualityComparer<unknown> {
|
|
107
|
+
/**
|
|
108
|
+
* Creates a comparer with its own numbering of objects.
|
|
109
|
+
*/
|
|
110
|
+
public constructor();
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Tells whether two values are the same by SameValueZero.
|
|
114
|
+
*/
|
|
115
|
+
public equals(left: unknown, right: unknown): boolean;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Returns the FNV-1a hash of a primitive's text, or this comparer's number
|
|
119
|
+
* for an object or a function.
|
|
120
|
+
*/
|
|
121
|
+
public hash(value: unknown): number;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* An equality that compares a key of each value; {@link EqualityComparers.by}
|
|
126
|
+
* builds one.
|
|
127
|
+
*
|
|
128
|
+
* @template T The type of the values compared.
|
|
129
|
+
* @template TKey The type of the keys compared.
|
|
130
|
+
*/
|
|
131
|
+
export declare class KeyEqualityComparer<T, TKey> implements IEqualityComparer<T> {
|
|
132
|
+
/**
|
|
133
|
+
* Creates an equality that compares the keys of values.
|
|
134
|
+
*
|
|
135
|
+
* @param key Selects the key compared. It is called on each value compared and hashed.
|
|
136
|
+
* @param comparer The equality of the keys.
|
|
137
|
+
*/
|
|
138
|
+
public constructor(key: (item: T) => TKey, comparer: IEqualityComparer<TKey>);
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Tells whether the keys of two values are equal.
|
|
142
|
+
*/
|
|
143
|
+
public equals(left: T, right: T): boolean;
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Returns the hash of the value's key.
|
|
147
|
+
*/
|
|
148
|
+
public hash(value: T): number;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* One entry of a {@link Dictionary}: a key and its value.
|
|
153
|
+
*
|
|
154
|
+
* @template TKey The type of the key.
|
|
155
|
+
* @template TValue The type of the value.
|
|
156
|
+
*/
|
|
157
|
+
export declare class KeyValuePair<TKey, TValue> {
|
|
158
|
+
/**
|
|
159
|
+
* Pairs a key with its value.
|
|
160
|
+
*
|
|
161
|
+
* @param key The entry's key.
|
|
162
|
+
* @param value The value stored under the key.
|
|
163
|
+
* @example
|
|
164
|
+
* ```ts
|
|
165
|
+
* import { Dictionary, KeyValuePair } from "@noldova/context.collections";
|
|
166
|
+
*
|
|
167
|
+
* const ages = new Dictionary([new KeyValuePair("Leo", 7)]);
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
public constructor(key: TKey, value: TValue);
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* The entry's key.
|
|
174
|
+
*/
|
|
175
|
+
public readonly key: TKey;
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* The value stored under the key.
|
|
179
|
+
*/
|
|
180
|
+
public readonly value: TValue;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* The default ordering of values, and ways to build orderings from it.
|
|
185
|
+
*/
|
|
186
|
+
export declare class Comparer {
|
|
187
|
+
/**
|
|
188
|
+
* Orders two values of the same kind: numbers and bigints by value, strings by
|
|
189
|
+
* UTF-16 code unit as `<` does, `false` before `true`, and Dates by time.
|
|
190
|
+
* `undefined` comes before `null`, and both come before every other value.
|
|
191
|
+
* `NaN` comes before every number and equals `NaN`; `-0` equals `0`.
|
|
192
|
+
*
|
|
193
|
+
* @param left The first value.
|
|
194
|
+
* @param right The second value.
|
|
195
|
+
* @returns `-1`, `0` or `1`.
|
|
196
|
+
* @throws {ArgumentException} When the values are of kinds this order doesn't
|
|
197
|
+
* cover, such as two objects or a number and a string.
|
|
198
|
+
*
|
|
199
|
+
* @remarks
|
|
200
|
+
* The string order is the same on every locale and host. For the order of
|
|
201
|
+
* Unicode code points, which differs past U+FFFF, pass
|
|
202
|
+
* `CodePointComparer.compare` from `@noldova/context.text`.
|
|
203
|
+
*
|
|
204
|
+
* @example
|
|
205
|
+
* ```ts
|
|
206
|
+
* import { Comparer } from "@noldova/context.collections";
|
|
207
|
+
*
|
|
208
|
+
* Comparer.compare(1, 2); // -1
|
|
209
|
+
* Comparer.compare("b", "a"); // 1
|
|
210
|
+
* Comparer.compare(null, 0); // -1
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
public static compare<T>(left: T, right: T): number;
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Reverses an ordering.
|
|
217
|
+
*
|
|
218
|
+
* @param comparison The ordering to reverse.
|
|
219
|
+
* @returns An ordering that puts `right` first wherever `comparison` puts `left` first.
|
|
220
|
+
* @example
|
|
221
|
+
* ```ts
|
|
222
|
+
* import { Comparer } from "@noldova/context.collections";
|
|
223
|
+
*
|
|
224
|
+
* [1, 3, 2].sort(Comparer.descending(Comparer.compare)); // [3, 2, 1]
|
|
225
|
+
* ```
|
|
226
|
+
*/
|
|
227
|
+
public static descending<T>(comparison: Comparison<T>): Comparison<T>;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* The default key equality, and ways to build equalities from it.
|
|
232
|
+
*/
|
|
233
|
+
export declare class EqualityComparers {
|
|
234
|
+
/**
|
|
235
|
+
* SameValueZero, the equality `Map` and `Set` use: primitives by value, with
|
|
236
|
+
* `NaN` equal to `NaN` and `-0` equal to `0`, and objects and functions by
|
|
237
|
+
* reference. Its hash reads a primitive's text and numbers each object the
|
|
238
|
+
* first time it hashes it, holding no reference that keeps the object alive.
|
|
239
|
+
*
|
|
240
|
+
* @example
|
|
241
|
+
* ```ts
|
|
242
|
+
* import { EqualityComparers } from "@noldova/context.collections";
|
|
243
|
+
*
|
|
244
|
+
* EqualityComparers.default.equals(Number.NaN, Number.NaN); // true
|
|
245
|
+
* EqualityComparers.default.equals(new Date(0), new Date(0)); // false: two objects.
|
|
246
|
+
* ```
|
|
247
|
+
*/
|
|
248
|
+
public static readonly default: DefaultEqualityComparer;
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Builds an equality that compares a key of each value.
|
|
252
|
+
*
|
|
253
|
+
* @param key Selects the key compared. It is called on each value compared and hashed.
|
|
254
|
+
* @param comparer The equality of the keys. Omitted, it is {@link EqualityComparers.default}.
|
|
255
|
+
* @returns An equality that calls two values equal when their keys are.
|
|
256
|
+
* @example
|
|
257
|
+
* ```ts
|
|
258
|
+
* import { EqualityComparers, HashSet } from "@noldova/context.collections";
|
|
259
|
+
*
|
|
260
|
+
* const names = new HashSet(["Ana", "ana", "Leo"], EqualityComparers.by((t: string) => t.toLowerCase()));
|
|
261
|
+
* names.count(); // 2
|
|
262
|
+
* ```
|
|
263
|
+
*/
|
|
264
|
+
public static by<T, TKey>(key: (item: T) => TKey, comparer?: IEqualityComparer<TKey>): KeyEqualityComparer<T, TKey>;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* The base of every collection and query: a sequence that can be enumerated
|
|
269
|
+
* any number of times, with the query operators.
|
|
270
|
+
*
|
|
271
|
+
* @template T The type of the elements.
|
|
272
|
+
*
|
|
273
|
+
* @remarks
|
|
274
|
+
* Operators that return an {@link Enumerable} are deferred: they run nothing
|
|
275
|
+
* until the result is enumerated, and they run again on each enumeration, so
|
|
276
|
+
* they see the source as it is then. The other operators run at once.
|
|
277
|
+
* `toArray`, `toList`, `toHashSet` and `toDictionary` copy the elements into a
|
|
278
|
+
* new collection that doesn't follow later changes to the source.
|
|
279
|
+
*
|
|
280
|
+
* Methods that require an element throw when there is none: the `…OrDefault`
|
|
281
|
+
* form returns `undefined` instead, since `undefined` means that there is no value
|
|
282
|
+
* and `null` is a value someone set. An element that is `undefined` can't be
|
|
283
|
+
* told from no element there.
|
|
284
|
+
*
|
|
285
|
+
* @example
|
|
286
|
+
* ```ts
|
|
287
|
+
* import { Enumerable, List } from "@noldova/context.collections";
|
|
288
|
+
*
|
|
289
|
+
* const ages = new List([31, 42, 27]);
|
|
290
|
+
* ages.where(t => t < 40).orderBy(t => t).select(t => `${t} years`).toArray(); // ["27 years", "31 years"]
|
|
291
|
+
* Enumerable.from([1, 2, 3]).sum(); // 6
|
|
292
|
+
* ages.firstOrDefault(t => t > 50); // undefined
|
|
293
|
+
* ```
|
|
294
|
+
*/
|
|
295
|
+
export declare abstract class Enumerable<T> implements Iterable<T> {
|
|
296
|
+
/**
|
|
297
|
+
* Wraps any iterable, such as an array, a `Map` or a generator, in the query operators.
|
|
298
|
+
*
|
|
299
|
+
* @param source The elements. Each enumeration of the result enumerates the
|
|
300
|
+
* source again, so a one-time iterable, such as a generator object, yields its
|
|
301
|
+
* elements once.
|
|
302
|
+
* @returns A deferred sequence of the source's elements.
|
|
303
|
+
* @example
|
|
304
|
+
* ```ts
|
|
305
|
+
* import { Enumerable } from "@noldova/context.collections";
|
|
306
|
+
*
|
|
307
|
+
* Enumerable.from(new Set([1, 2])).select(t => t * 10).toArray(); // [10, 20]
|
|
308
|
+
* ```
|
|
309
|
+
*/
|
|
310
|
+
public static from<T>(source: Iterable<T>): Enumerable<T>;
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Returns a sequence with no elements.
|
|
314
|
+
*/
|
|
315
|
+
public static empty<T>(): Enumerable<T>;
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Returns `count` consecutive integers from `start`.
|
|
319
|
+
*
|
|
320
|
+
* @param start The first integer.
|
|
321
|
+
* @param count How many integers.
|
|
322
|
+
* @throws {ArgumentOutOfRangeException} When `start` isn't an integer, `count`
|
|
323
|
+
* isn't a non-negative integer, or an integer of the range isn't a safe integer.
|
|
324
|
+
* @example
|
|
325
|
+
* ```ts
|
|
326
|
+
* import { Enumerable } from "@noldova/context.collections";
|
|
327
|
+
*
|
|
328
|
+
* Enumerable.range(5, 3).toArray(); // [5, 6, 7]
|
|
329
|
+
* ```
|
|
330
|
+
*/
|
|
331
|
+
public static range(start: number, count: number): Enumerable<number>;
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* Returns one value `count` times.
|
|
335
|
+
*
|
|
336
|
+
* @throws {ArgumentOutOfRangeException} When `count` isn't a non-negative integer.
|
|
337
|
+
*/
|
|
338
|
+
public static repeat<T>(value: T, count: number): Enumerable<T>;
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* Starts an enumeration of the elements.
|
|
342
|
+
*/
|
|
343
|
+
public abstract [Symbol.iterator](): Iterator<T>;
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Keeps the elements that match. A type guard narrows the result's element type.
|
|
347
|
+
*
|
|
348
|
+
* @param predicate Called with each element and its zero-based position in this sequence.
|
|
349
|
+
* @example
|
|
350
|
+
* ```ts
|
|
351
|
+
* import "@noldova/context.core";
|
|
352
|
+
* import { Enumerable } from "@noldova/context.collections";
|
|
353
|
+
*
|
|
354
|
+
* Enumerable.from([1, null, 2]).where(t => !Object.isNull(t)).toArray(); // [1, 2], typed number[].
|
|
355
|
+
* ```
|
|
356
|
+
*/
|
|
357
|
+
public where<TResult extends T>(predicate: (item: T, index: number) => item is TResult): Enumerable<TResult>;
|
|
358
|
+
public where(predicate: (item: T, index: number) => boolean): Enumerable<T>;
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* Maps each element.
|
|
362
|
+
*
|
|
363
|
+
* @param selector Called with each element and its zero-based position.
|
|
364
|
+
*/
|
|
365
|
+
public select<TResult>(selector: (item: T, index: number) => TResult): Enumerable<TResult>;
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* Maps each element to a sequence and joins those sequences into one.
|
|
369
|
+
*
|
|
370
|
+
* @param selector Called with each element and its zero-based position.
|
|
371
|
+
* @example
|
|
372
|
+
* ```ts
|
|
373
|
+
* import { Enumerable } from "@noldova/context.collections";
|
|
374
|
+
*
|
|
375
|
+
* Enumerable.from(["ab", "c"]).selectMany(t => t).toArray(); // ["a", "b", "c"]
|
|
376
|
+
* ```
|
|
377
|
+
*/
|
|
378
|
+
public selectMany<TResult>(selector: (item: T, index: number) => Iterable<TResult>): Enumerable<TResult>;
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Pairs each element with each element of `inner` that has an equal key, in
|
|
382
|
+
* this sequence's order and then `inner`'s. An element with no match is left out.
|
|
383
|
+
*
|
|
384
|
+
* @param inner The elements to match. It is read once, on each enumeration.
|
|
385
|
+
* @param outerKey Selects the key of this sequence's elements.
|
|
386
|
+
* @param innerKey Selects the key of `inner`'s elements.
|
|
387
|
+
* @param result Builds a result from a matched pair.
|
|
388
|
+
* @param comparer The key equality. Omitted, it is SameValueZero.
|
|
389
|
+
* @example
|
|
390
|
+
* ```ts
|
|
391
|
+
* import { Enumerable, KeyValuePair } from "@noldova/context.collections";
|
|
392
|
+
*
|
|
393
|
+
* const users = [new KeyValuePair(1, "Ana")];
|
|
394
|
+
* const devices = [new KeyValuePair(1, "phone"), new KeyValuePair(1, "laptop")];
|
|
395
|
+
* Enumerable.from(users).join(devices, t => t.key, t => t.key, (user, device) => `${user.value} ${device.value}`).toArray();
|
|
396
|
+
* // ["Ana phone", "Ana laptop"]
|
|
397
|
+
* ```
|
|
398
|
+
*/
|
|
399
|
+
public join<TInner, TKey, TResult>(
|
|
400
|
+
inner: Iterable<TInner>,
|
|
401
|
+
outerKey: (item: T) => TKey,
|
|
402
|
+
innerKey: (item: TInner) => TKey,
|
|
403
|
+
result: (outer: T, inner: TInner) => TResult,
|
|
404
|
+
comparer?: IEqualityComparer<TKey>): Enumerable<TResult>;
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* Pairs each element with all elements of `inner` that have an equal key, an
|
|
408
|
+
* empty sequence when none do.
|
|
409
|
+
*
|
|
410
|
+
* @param inner The elements to match. It is read once, on each enumeration.
|
|
411
|
+
* @param outerKey Selects the key of this sequence's elements.
|
|
412
|
+
* @param innerKey Selects the key of `inner`'s elements.
|
|
413
|
+
* @param result Builds a result from an element and its matches, in `inner`'s order.
|
|
414
|
+
* @param comparer The key equality. Omitted, it is SameValueZero.
|
|
415
|
+
*/
|
|
416
|
+
public groupJoin<TInner, TKey, TResult>(
|
|
417
|
+
inner: Iterable<TInner>,
|
|
418
|
+
outerKey: (item: T) => TKey,
|
|
419
|
+
innerKey: (item: TInner) => TKey,
|
|
420
|
+
result: (outer: T, inner: Enumerable<TInner>) => TResult,
|
|
421
|
+
comparer?: IEqualityComparer<TKey>): Enumerable<TResult>;
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* Keeps the first of each set of equal elements.
|
|
425
|
+
*
|
|
426
|
+
* @param comparer The equality. Omitted, it is SameValueZero.
|
|
427
|
+
*/
|
|
428
|
+
public distinct(comparer?: IEqualityComparer<T>): Enumerable<T>;
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* Keeps the first element of each key.
|
|
432
|
+
*
|
|
433
|
+
* @param key Selects the key compared.
|
|
434
|
+
* @param comparer The key equality. Omitted, it is SameValueZero.
|
|
435
|
+
*/
|
|
436
|
+
public distinctBy<TKey>(key: (item: T) => TKey, comparer?: IEqualityComparer<TKey>): Enumerable<T>;
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* The distinct elements of this sequence and then of `other`.
|
|
440
|
+
*
|
|
441
|
+
* @param comparer The equality. Omitted, it is SameValueZero.
|
|
442
|
+
*/
|
|
443
|
+
public union(other: Iterable<T>, comparer?: IEqualityComparer<T>): Enumerable<T>;
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* The distinct elements of this sequence that `other` also holds, in this sequence's order.
|
|
447
|
+
*
|
|
448
|
+
* @param comparer The equality. Omitted, it is SameValueZero.
|
|
449
|
+
*/
|
|
450
|
+
public intersect(other: Iterable<T>, comparer?: IEqualityComparer<T>): Enumerable<T>;
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* The distinct elements of this sequence that `other` doesn't hold.
|
|
454
|
+
*
|
|
455
|
+
* @param comparer The equality. Omitted, it is SameValueZero.
|
|
456
|
+
*/
|
|
457
|
+
public except(other: Iterable<T>, comparer?: IEqualityComparer<T>): Enumerable<T>;
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* The elements of this sequence and then of `other`.
|
|
461
|
+
*/
|
|
462
|
+
public concat(other: Iterable<T>): Enumerable<T>;
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* The elements of this sequence and then `item`.
|
|
466
|
+
*/
|
|
467
|
+
public append(item: T): Enumerable<T>;
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* `item` and then the elements of this sequence.
|
|
471
|
+
*/
|
|
472
|
+
public prepend(item: T): Enumerable<T>;
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* Leaves out the first `count` elements; a count of zero or less leaves out none.
|
|
476
|
+
*
|
|
477
|
+
* @throws {ArgumentOutOfRangeException} When `count` isn't an integer.
|
|
478
|
+
*/
|
|
479
|
+
public skip(count: number): Enumerable<T>;
|
|
480
|
+
|
|
481
|
+
/**
|
|
482
|
+
* Keeps the first `count` elements; a count of zero or less keeps none.
|
|
483
|
+
*
|
|
484
|
+
* @throws {ArgumentOutOfRangeException} When `count` isn't an integer.
|
|
485
|
+
* @example
|
|
486
|
+
* ```ts
|
|
487
|
+
* import { Enumerable } from "@noldova/context.collections";
|
|
488
|
+
*
|
|
489
|
+
* Enumerable.range(1, 100).skip(20).take(10).toArray(); // [21, …, 30]
|
|
490
|
+
* ```
|
|
491
|
+
*/
|
|
492
|
+
public take(count: number): Enumerable<T>;
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* Leaves out elements while they match, and keeps the rest from the first that doesn't.
|
|
496
|
+
*
|
|
497
|
+
* @param predicate Called with each element and its zero-based position until it returns false.
|
|
498
|
+
*/
|
|
499
|
+
public skipWhile(predicate: (item: T, index: number) => boolean): Enumerable<T>;
|
|
500
|
+
|
|
501
|
+
/**
|
|
502
|
+
* Keeps elements while they match, and stops at the first that doesn't.
|
|
503
|
+
*
|
|
504
|
+
* @param predicate Called with each element and its zero-based position until it returns false.
|
|
505
|
+
*/
|
|
506
|
+
public takeWhile(predicate: (item: T, index: number) => boolean): Enumerable<T>;
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* Leaves out the last `count` elements. It reads the whole sequence before
|
|
510
|
+
* it yields the first element.
|
|
511
|
+
*
|
|
512
|
+
* @throws {ArgumentOutOfRangeException} When `count` isn't an integer.
|
|
513
|
+
*/
|
|
514
|
+
public skipLast(count: number): Enumerable<T>;
|
|
515
|
+
|
|
516
|
+
/**
|
|
517
|
+
* Keeps the last `count` elements. It reads the whole sequence first.
|
|
518
|
+
*
|
|
519
|
+
* @throws {ArgumentOutOfRangeException} When `count` isn't an integer.
|
|
520
|
+
*/
|
|
521
|
+
public takeLast(count: number): Enumerable<T>;
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* The elements in the opposite order. It reads the whole sequence first.
|
|
525
|
+
*/
|
|
526
|
+
public reverse(): Enumerable<T>;
|
|
527
|
+
|
|
528
|
+
/**
|
|
529
|
+
* Splits the elements into arrays of `size`; the last may be shorter.
|
|
530
|
+
*
|
|
531
|
+
* @throws {ArgumentOutOfRangeException} When `size` isn't a positive integer.
|
|
532
|
+
* @example
|
|
533
|
+
* ```ts
|
|
534
|
+
* import { Enumerable } from "@noldova/context.collections";
|
|
535
|
+
*
|
|
536
|
+
* Enumerable.range(1, 5).chunk(2).toArray(); // [[1, 2], [3, 4], [5]]
|
|
537
|
+
* ```
|
|
538
|
+
*/
|
|
539
|
+
public chunk(size: number): Enumerable<readonly T[]>;
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* Combines the elements at the same position in this sequence and `other`,
|
|
543
|
+
* and stops at the end of the shorter sequence.
|
|
544
|
+
*
|
|
545
|
+
* @param other The sequence to read alongside this one.
|
|
546
|
+
* @param result Builds one result from the two elements at a position.
|
|
547
|
+
* @example
|
|
548
|
+
* ```ts
|
|
549
|
+
* import { Enumerable } from "@noldova/context.collections";
|
|
550
|
+
*
|
|
551
|
+
* Enumerable.from(["a", "b", "c"]).zip([1, 2], (letter, count) => letter.repeat(count)).toArray(); // ["a", "bb"]
|
|
552
|
+
* ```
|
|
553
|
+
*/
|
|
554
|
+
public zip<TOther, TResult>(other: Iterable<TOther>, result: (first: T, second: TOther) => TResult): Enumerable<TResult>;
|
|
555
|
+
|
|
556
|
+
/**
|
|
557
|
+
* The first element, or the first that matches.
|
|
558
|
+
*
|
|
559
|
+
* @throws {InvalidOperationException} When there is none.
|
|
560
|
+
*/
|
|
561
|
+
public first(predicate?: (item: T) => boolean): T;
|
|
562
|
+
|
|
563
|
+
/**
|
|
564
|
+
* The first element, or the first that matches; `undefined` when there is none.
|
|
565
|
+
*/
|
|
566
|
+
public firstOrDefault(predicate?: (item: T) => boolean): T | undefined;
|
|
567
|
+
|
|
568
|
+
/**
|
|
569
|
+
* The last element, or the last that matches.
|
|
570
|
+
*
|
|
571
|
+
* @throws {InvalidOperationException} When there is none.
|
|
572
|
+
*/
|
|
573
|
+
public last(predicate?: (item: T) => boolean): T;
|
|
574
|
+
|
|
575
|
+
/**
|
|
576
|
+
* The last element, or the last that matches; `undefined` when there is none.
|
|
577
|
+
*/
|
|
578
|
+
public lastOrDefault(predicate?: (item: T) => boolean): T | undefined;
|
|
579
|
+
|
|
580
|
+
/**
|
|
581
|
+
* The only element, or the only one that matches.
|
|
582
|
+
*
|
|
583
|
+
* @throws {InvalidOperationException} When there is none, or more than one.
|
|
584
|
+
*/
|
|
585
|
+
public single(predicate?: (item: T) => boolean): T;
|
|
586
|
+
|
|
587
|
+
/**
|
|
588
|
+
* The only element, or the only one that matches; `undefined` when there is none.
|
|
589
|
+
*
|
|
590
|
+
* @throws {InvalidOperationException} When there is more than one.
|
|
591
|
+
*/
|
|
592
|
+
public singleOrDefault(predicate?: (item: T) => boolean): T | undefined;
|
|
593
|
+
|
|
594
|
+
/**
|
|
595
|
+
* The element at a zero-based position.
|
|
596
|
+
*
|
|
597
|
+
* @throws {ArgumentOutOfRangeException} When there is no element there; a
|
|
598
|
+
* negative or fractional position throws before the sequence is read.
|
|
599
|
+
*/
|
|
600
|
+
public elementAt(index: number): T;
|
|
601
|
+
|
|
602
|
+
/**
|
|
603
|
+
* The element at a zero-based position; `undefined` when there is none, and at
|
|
604
|
+
* once, without reading the sequence, for a negative or fractional position.
|
|
605
|
+
*/
|
|
606
|
+
public elementAtOrDefault(index: number): T | undefined;
|
|
607
|
+
|
|
608
|
+
/**
|
|
609
|
+
* Tells whether there is an element, or one that matches.
|
|
610
|
+
*/
|
|
611
|
+
public any(predicate?: (item: T) => boolean): boolean;
|
|
612
|
+
|
|
613
|
+
/**
|
|
614
|
+
* Tells whether every element matches; true for an empty sequence.
|
|
615
|
+
*/
|
|
616
|
+
public all(predicate: (item: T) => boolean): boolean;
|
|
617
|
+
|
|
618
|
+
/**
|
|
619
|
+
* Tells whether an element equals `item`.
|
|
620
|
+
*
|
|
621
|
+
* @param comparer The equality. Omitted, it is SameValueZero; a {@link HashSet}
|
|
622
|
+
* then uses its own equality.
|
|
623
|
+
*/
|
|
624
|
+
public contains(item: T, comparer?: IEqualityComparer<T>): boolean;
|
|
625
|
+
|
|
626
|
+
/**
|
|
627
|
+
* Counts the elements, or those that match. A collection counts its own
|
|
628
|
+
* elements at once; other sequences enumerate.
|
|
629
|
+
*/
|
|
630
|
+
public count(predicate?: (item: T) => boolean): number;
|
|
631
|
+
|
|
632
|
+
/**
|
|
633
|
+
* Adds the numbers, or the numbers `selector` returns; zero for an empty sequence.
|
|
634
|
+
*
|
|
635
|
+
* @throws {InvalidOperationException} When a value isn't a number, as only an
|
|
636
|
+
* untyped caller can pass.
|
|
637
|
+
*/
|
|
638
|
+
public sum(this: Enumerable<number>): number;
|
|
639
|
+
public sum(selector: (item: T) => number): number;
|
|
640
|
+
|
|
641
|
+
/**
|
|
642
|
+
* The mean of the numbers, or of the numbers `selector` returns.
|
|
643
|
+
*
|
|
644
|
+
* @throws {InvalidOperationException} When the sequence is empty, or a value isn't a number.
|
|
645
|
+
*/
|
|
646
|
+
public average(this: Enumerable<number>): number;
|
|
647
|
+
public average(selector: (item: T) => number): number;
|
|
648
|
+
|
|
649
|
+
/**
|
|
650
|
+
* The smallest element, the first of equal ones.
|
|
651
|
+
*
|
|
652
|
+
* @param comparison The order. Omitted, it is {@link Comparer.compare}.
|
|
653
|
+
* @throws {InvalidOperationException} When the sequence is empty.
|
|
654
|
+
*/
|
|
655
|
+
public min(comparison?: Comparison<T>): T;
|
|
656
|
+
|
|
657
|
+
/**
|
|
658
|
+
* The largest element, the first of equal ones.
|
|
659
|
+
*
|
|
660
|
+
* @param comparison The order. Omitted, it is {@link Comparer.compare}.
|
|
661
|
+
* @throws {InvalidOperationException} When the sequence is empty.
|
|
662
|
+
*/
|
|
663
|
+
public max(comparison?: Comparison<T>): T;
|
|
664
|
+
|
|
665
|
+
/**
|
|
666
|
+
* The element with the smallest key, the first of equal ones.
|
|
667
|
+
*
|
|
668
|
+
* @param comparison The order of the keys. Omitted, it is {@link Comparer.compare}.
|
|
669
|
+
* @throws {InvalidOperationException} When the sequence is empty.
|
|
670
|
+
*/
|
|
671
|
+
public minBy<TKey>(key: (item: T) => TKey, comparison?: Comparison<TKey>): T;
|
|
672
|
+
|
|
673
|
+
/**
|
|
674
|
+
* The element with the largest key, the first of equal ones.
|
|
675
|
+
*
|
|
676
|
+
* @param comparison The order of the keys. Omitted, it is {@link Comparer.compare}.
|
|
677
|
+
* @throws {InvalidOperationException} When the sequence is empty.
|
|
678
|
+
*/
|
|
679
|
+
public maxBy<TKey>(key: (item: T) => TKey, comparison?: Comparison<TKey>): T;
|
|
680
|
+
|
|
681
|
+
/**
|
|
682
|
+
* Folds the elements into one value, starting from `seed`.
|
|
683
|
+
*/
|
|
684
|
+
public aggregate<TAccumulate>(seed: TAccumulate, accumulator: (total: TAccumulate, item: T) => TAccumulate): TAccumulate;
|
|
685
|
+
|
|
686
|
+
/**
|
|
687
|
+
* Tells whether both sequences have equal elements in the same order.
|
|
688
|
+
*
|
|
689
|
+
* @param comparer The equality. Omitted, it is SameValueZero.
|
|
690
|
+
*/
|
|
691
|
+
public sequenceEqual(other: Iterable<T>, comparer?: IEqualityComparer<T>): boolean;
|
|
692
|
+
|
|
693
|
+
/**
|
|
694
|
+
* Orders the elements by a key, keeping the order of elements with equal keys.
|
|
695
|
+
* It reads the whole sequence first, on each enumeration, and calls `key` once
|
|
696
|
+
* for each element.
|
|
697
|
+
*
|
|
698
|
+
* @param comparison The order of the keys. Omitted, it is {@link Comparer.compare}.
|
|
699
|
+
* @example
|
|
700
|
+
* ```ts
|
|
701
|
+
* import { Enumerable } from "@noldova/context.collections";
|
|
702
|
+
*
|
|
703
|
+
* Enumerable.from(["bb", "b", "ab", "a"]).orderBy(t => t.length).thenBy(t => t).toArray(); // ["a", "b", "ab", "bb"]
|
|
704
|
+
* ```
|
|
705
|
+
*/
|
|
706
|
+
public orderBy<TKey>(key: (item: T) => TKey, comparison?: Comparison<TKey>): OrderedEnumerable<T>;
|
|
707
|
+
|
|
708
|
+
/**
|
|
709
|
+
* Orders the elements by a key, largest first, keeping the order of elements with equal keys.
|
|
710
|
+
*
|
|
711
|
+
* @param comparison The order of the keys. Omitted, it is {@link Comparer.compare}.
|
|
712
|
+
*/
|
|
713
|
+
public orderByDescending<TKey>(key: (item: T) => TKey, comparison?: Comparison<TKey>): OrderedEnumerable<T>;
|
|
714
|
+
|
|
715
|
+
/**
|
|
716
|
+
* Groups the elements by key, in the order each key first appears. It reads
|
|
717
|
+
* the whole sequence first, on each enumeration.
|
|
718
|
+
*
|
|
719
|
+
* @param comparer The key equality. Omitted, it is SameValueZero.
|
|
720
|
+
* @example
|
|
721
|
+
* ```ts
|
|
722
|
+
* import { Enumerable } from "@noldova/context.collections";
|
|
723
|
+
*
|
|
724
|
+
* Enumerable.from(["apple", "avocado", "banana"]).groupBy(t => t[0])
|
|
725
|
+
* .select(t => `${t.key}: ${t.count()}`).toArray(); // ["a: 2", "b: 1"]
|
|
726
|
+
* ```
|
|
727
|
+
*/
|
|
728
|
+
public groupBy<TKey>(key: (item: T) => TKey, comparer?: IEqualityComparer<TKey>): Enumerable<Grouping<TKey, T>>;
|
|
729
|
+
|
|
730
|
+
/**
|
|
731
|
+
* Copies the elements into a new array.
|
|
732
|
+
*/
|
|
733
|
+
public toArray(): T[];
|
|
734
|
+
|
|
735
|
+
/**
|
|
736
|
+
* Copies the elements into a new {@link List}. The elements can't be
|
|
737
|
+
* `undefined`, which a list uses to mean no element.
|
|
738
|
+
*/
|
|
739
|
+
public toList<TItem extends {} | null>(this: Enumerable<TItem>): List<TItem>;
|
|
740
|
+
|
|
741
|
+
/**
|
|
742
|
+
* Copies the distinct elements into a new {@link HashSet}.
|
|
743
|
+
*
|
|
744
|
+
* @param comparer The set's equality. Omitted, it is SameValueZero.
|
|
745
|
+
*/
|
|
746
|
+
public toHashSet(comparer?: IEqualityComparer<T>): HashSet<T>;
|
|
747
|
+
|
|
748
|
+
/**
|
|
749
|
+
* Copies the elements into a new {@link Dictionary}.
|
|
750
|
+
*
|
|
751
|
+
* @param key Selects each entry's key.
|
|
752
|
+
* @param value Selects each entry's value; it can't return `undefined`.
|
|
753
|
+
* @param comparer The dictionary's key equality. Omitted, it is SameValueZero.
|
|
754
|
+
* @throws {ArgumentException} When two elements have equal keys.
|
|
755
|
+
* @example
|
|
756
|
+
* ```ts
|
|
757
|
+
* import { Enumerable } from "@noldova/context.collections";
|
|
758
|
+
*
|
|
759
|
+
* const lengths = Enumerable.from(["Ana", "Mia"]).toDictionary(t => t, t => t.length);
|
|
760
|
+
* lengths.get("Mia"); // 3
|
|
761
|
+
* ```
|
|
762
|
+
*/
|
|
763
|
+
public toDictionary<TKey, TValue extends {} | null>(key: (item: T) => TKey, value: (item: T) => TValue, comparer?: IEqualityComparer<TKey>): Dictionary<TKey, TValue>;
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
/**
|
|
767
|
+
* A sequence ordered by `orderBy` or `orderByDescending`, which further keys can refine.
|
|
768
|
+
*
|
|
769
|
+
* @template T The type of the elements.
|
|
770
|
+
*/
|
|
771
|
+
export declare class OrderedEnumerable<T> extends Enumerable<T> {
|
|
772
|
+
private constructor();
|
|
773
|
+
|
|
774
|
+
/**
|
|
775
|
+
* Starts an enumeration of the ordered elements.
|
|
776
|
+
*/
|
|
777
|
+
public [Symbol.iterator](): Iterator<T>;
|
|
778
|
+
|
|
779
|
+
/**
|
|
780
|
+
* Orders elements that the earlier keys leave equal by another key.
|
|
781
|
+
*
|
|
782
|
+
* @param comparison The order of the keys. Omitted, it is {@link Comparer.compare}.
|
|
783
|
+
*/
|
|
784
|
+
public thenBy<TKey>(key: (item: T) => TKey, comparison?: Comparison<TKey>): OrderedEnumerable<T>;
|
|
785
|
+
|
|
786
|
+
/**
|
|
787
|
+
* Orders elements that the earlier keys leave equal by another key, largest first.
|
|
788
|
+
*
|
|
789
|
+
* @param comparison The order of the keys. Omitted, it is {@link Comparer.compare}.
|
|
790
|
+
*/
|
|
791
|
+
public thenByDescending<TKey>(key: (item: T) => TKey, comparison?: Comparison<TKey>): OrderedEnumerable<T>;
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
/**
|
|
795
|
+
* The elements of one key, from `groupBy`, in their sequence's order.
|
|
796
|
+
*
|
|
797
|
+
* @template TKey The type of the key.
|
|
798
|
+
* @template T The type of the elements.
|
|
799
|
+
*/
|
|
800
|
+
export declare class Grouping<TKey, T> extends Enumerable<T> {
|
|
801
|
+
private constructor();
|
|
802
|
+
|
|
803
|
+
/**
|
|
804
|
+
* The key the elements share.
|
|
805
|
+
*/
|
|
806
|
+
public readonly key: TKey;
|
|
807
|
+
|
|
808
|
+
/**
|
|
809
|
+
* Starts an enumeration of the group's elements.
|
|
810
|
+
*/
|
|
811
|
+
public [Symbol.iterator](): Iterator<T>;
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
/**
|
|
815
|
+
* What can be read from a list: the contract {@link List} and
|
|
816
|
+
* {@link ReadOnlyList} implement, for a parameter that only reads a list.
|
|
817
|
+
*
|
|
818
|
+
* @template T The type of the elements; not `undefined`, which means no element.
|
|
819
|
+
*/
|
|
820
|
+
export declare interface IReadOnlyList<T extends {} | null> extends Enumerable<T> {
|
|
821
|
+
/**
|
|
822
|
+
* The element at a zero-based position.
|
|
823
|
+
*
|
|
824
|
+
* @throws {ArgumentOutOfRangeException} When there is no element there.
|
|
825
|
+
*/
|
|
826
|
+
get(index: number): T;
|
|
827
|
+
|
|
828
|
+
/**
|
|
829
|
+
* The element at a zero-based position; `undefined` when there is none.
|
|
830
|
+
*/
|
|
831
|
+
tryGet(index: number): T | undefined;
|
|
832
|
+
|
|
833
|
+
/**
|
|
834
|
+
* The position of the first element equal to `item` by SameValueZero, or `-1`.
|
|
835
|
+
*/
|
|
836
|
+
indexOf(item: T): number;
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
/**
|
|
840
|
+
* What can be read from a dictionary: the contract {@link Dictionary} and
|
|
841
|
+
* {@link ReadOnlyDictionary} implement, for a parameter that only reads a
|
|
842
|
+
* dictionary.
|
|
843
|
+
*
|
|
844
|
+
* @template TKey The type of the keys.
|
|
845
|
+
* @template TValue The type of the values; not `undefined`, which means no value.
|
|
846
|
+
*/
|
|
847
|
+
export declare interface IReadOnlyDictionary<TKey, TValue extends {} | null> extends Enumerable<KeyValuePair<TKey, TValue>> {
|
|
848
|
+
/**
|
|
849
|
+
* The value of a key.
|
|
850
|
+
*
|
|
851
|
+
* @throws {KeyNotFoundException} When the dictionary has no such key.
|
|
852
|
+
*/
|
|
853
|
+
get(key: TKey): TValue;
|
|
854
|
+
|
|
855
|
+
/**
|
|
856
|
+
* The value of a key; `undefined` when the dictionary has no such key.
|
|
857
|
+
*/
|
|
858
|
+
tryGet(key: TKey): TValue | undefined;
|
|
859
|
+
|
|
860
|
+
/**
|
|
861
|
+
* Tells whether the dictionary has a key.
|
|
862
|
+
*/
|
|
863
|
+
containsKey(key: TKey): boolean;
|
|
864
|
+
|
|
865
|
+
/**
|
|
866
|
+
* The keys, in the order they were added; it follows later changes.
|
|
867
|
+
*/
|
|
868
|
+
keys(): Enumerable<TKey>;
|
|
869
|
+
|
|
870
|
+
/**
|
|
871
|
+
* The values, in their keys' order; it follows later changes.
|
|
872
|
+
*/
|
|
873
|
+
values(): Enumerable<TValue>;
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
/**
|
|
877
|
+
* What can be read from a set: the contract {@link HashSet} and
|
|
878
|
+
* {@link ReadOnlySet} implement, for a parameter that only reads a set.
|
|
879
|
+
*
|
|
880
|
+
* @template T The type of the elements.
|
|
881
|
+
*/
|
|
882
|
+
export declare interface IReadOnlySet<T> extends Enumerable<T> {
|
|
883
|
+
/**
|
|
884
|
+
* Tells whether `other` holds every element of this set.
|
|
885
|
+
*/
|
|
886
|
+
isSubsetOf(other: Iterable<T>): boolean;
|
|
887
|
+
|
|
888
|
+
/**
|
|
889
|
+
* Tells whether this set holds every element of `other`.
|
|
890
|
+
*/
|
|
891
|
+
isSupersetOf(other: Iterable<T>): boolean;
|
|
892
|
+
|
|
893
|
+
/**
|
|
894
|
+
* Tells whether this set and `other` share an element.
|
|
895
|
+
*/
|
|
896
|
+
overlaps(other: Iterable<T>): boolean;
|
|
897
|
+
|
|
898
|
+
/**
|
|
899
|
+
* Tells whether this set and `other` hold the same elements, ignoring order and repeats.
|
|
900
|
+
*/
|
|
901
|
+
setEquals(other: Iterable<T>): boolean;
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
/**
|
|
905
|
+
* A list that can be read but not changed through this view, which
|
|
906
|
+
* {@link List.asReadOnly} returns.
|
|
907
|
+
*
|
|
908
|
+
* @template T The type of the elements; not `undefined`, which means no element.
|
|
909
|
+
*
|
|
910
|
+
* @remarks
|
|
911
|
+
* The view reads the list it wraps on each call, so it follows the list's
|
|
912
|
+
* later changes.
|
|
913
|
+
*/
|
|
914
|
+
export declare class ReadOnlyList<T extends {} | null> extends Enumerable<T> implements IReadOnlyList<T> {
|
|
915
|
+
/**
|
|
916
|
+
* Creates a view that reads a list.
|
|
917
|
+
*
|
|
918
|
+
* @param list The list to read.
|
|
919
|
+
*/
|
|
920
|
+
public constructor(list: IReadOnlyList<T>);
|
|
921
|
+
|
|
922
|
+
/**
|
|
923
|
+
* Starts an enumeration of the list's elements in order.
|
|
924
|
+
*/
|
|
925
|
+
public [Symbol.iterator](): Iterator<T>;
|
|
926
|
+
|
|
927
|
+
/**
|
|
928
|
+
* The element at a zero-based position.
|
|
929
|
+
*
|
|
930
|
+
* @throws {ArgumentOutOfRangeException} When there is no element there.
|
|
931
|
+
*/
|
|
932
|
+
public get(index: number): T;
|
|
933
|
+
|
|
934
|
+
/**
|
|
935
|
+
* The element at a zero-based position; `undefined` when there is none.
|
|
936
|
+
*/
|
|
937
|
+
public tryGet(index: number): T | undefined;
|
|
938
|
+
|
|
939
|
+
/**
|
|
940
|
+
* The position of the first element equal to `item` by SameValueZero, or `-1`.
|
|
941
|
+
*/
|
|
942
|
+
public indexOf(item: T): number;
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
/**
|
|
946
|
+
* A dictionary that can be read but not changed through this view, which
|
|
947
|
+
* {@link Dictionary.asReadOnly} returns.
|
|
948
|
+
*
|
|
949
|
+
* @template TKey The type of the keys.
|
|
950
|
+
* @template TValue The type of the values; not `undefined`, which means no value.
|
|
951
|
+
*
|
|
952
|
+
* @remarks
|
|
953
|
+
* The view reads the dictionary it wraps on each call, so it follows the
|
|
954
|
+
* dictionary's later changes.
|
|
955
|
+
*/
|
|
956
|
+
export declare class ReadOnlyDictionary<TKey, TValue extends {} | null> extends Enumerable<KeyValuePair<TKey, TValue>>
|
|
957
|
+
implements IReadOnlyDictionary<TKey, TValue> {
|
|
958
|
+
/**
|
|
959
|
+
* Creates a view that reads a dictionary.
|
|
960
|
+
*
|
|
961
|
+
* @param dictionary The dictionary to read.
|
|
962
|
+
*/
|
|
963
|
+
public constructor(dictionary: IReadOnlyDictionary<TKey, TValue>);
|
|
964
|
+
|
|
965
|
+
/**
|
|
966
|
+
* Starts an enumeration of the entries in the order their keys were added.
|
|
967
|
+
*/
|
|
968
|
+
public [Symbol.iterator](): Iterator<KeyValuePair<TKey, TValue>>;
|
|
969
|
+
|
|
970
|
+
/**
|
|
971
|
+
* The value of a key.
|
|
972
|
+
*
|
|
973
|
+
* @throws {KeyNotFoundException} When the dictionary has no such key.
|
|
974
|
+
*/
|
|
975
|
+
public get(key: TKey): TValue;
|
|
976
|
+
|
|
977
|
+
/**
|
|
978
|
+
* The value of a key; `undefined` when the dictionary has no such key.
|
|
979
|
+
*/
|
|
980
|
+
public tryGet(key: TKey): TValue | undefined;
|
|
981
|
+
|
|
982
|
+
/**
|
|
983
|
+
* Tells whether the dictionary has a key.
|
|
984
|
+
*/
|
|
985
|
+
public containsKey(key: TKey): boolean;
|
|
986
|
+
|
|
987
|
+
/**
|
|
988
|
+
* The keys, in the order they were added; it follows later changes.
|
|
989
|
+
*/
|
|
990
|
+
public keys(): Enumerable<TKey>;
|
|
991
|
+
|
|
992
|
+
/**
|
|
993
|
+
* The values, in their keys' order; it follows later changes.
|
|
994
|
+
*/
|
|
995
|
+
public values(): Enumerable<TValue>;
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
/**
|
|
999
|
+
* A set that can be read but not changed through this view, which
|
|
1000
|
+
* {@link HashSet.asReadOnly} returns.
|
|
1001
|
+
*
|
|
1002
|
+
* @template T The type of the elements.
|
|
1003
|
+
*
|
|
1004
|
+
* @remarks
|
|
1005
|
+
* The view reads the set it wraps on each call, so it follows the set's later
|
|
1006
|
+
* changes.
|
|
1007
|
+
*/
|
|
1008
|
+
export declare class ReadOnlySet<T> extends Enumerable<T> implements IReadOnlySet<T> {
|
|
1009
|
+
/**
|
|
1010
|
+
* Creates a view that reads a set.
|
|
1011
|
+
*
|
|
1012
|
+
* @param set The set to read.
|
|
1013
|
+
*/
|
|
1014
|
+
public constructor(set: IReadOnlySet<T>);
|
|
1015
|
+
|
|
1016
|
+
/**
|
|
1017
|
+
* Starts an enumeration of the elements in the order they were added.
|
|
1018
|
+
*/
|
|
1019
|
+
public [Symbol.iterator](): Iterator<T>;
|
|
1020
|
+
|
|
1021
|
+
/**
|
|
1022
|
+
* Tells whether `other` holds every element of this set.
|
|
1023
|
+
*/
|
|
1024
|
+
public isSubsetOf(other: Iterable<T>): boolean;
|
|
1025
|
+
|
|
1026
|
+
/**
|
|
1027
|
+
* Tells whether this set holds every element of `other`.
|
|
1028
|
+
*/
|
|
1029
|
+
public isSupersetOf(other: Iterable<T>): boolean;
|
|
1030
|
+
|
|
1031
|
+
/**
|
|
1032
|
+
* Tells whether this set and `other` share an element.
|
|
1033
|
+
*/
|
|
1034
|
+
public overlaps(other: Iterable<T>): boolean;
|
|
1035
|
+
|
|
1036
|
+
/**
|
|
1037
|
+
* Tells whether this set and `other` hold the same elements, ignoring order and repeats.
|
|
1038
|
+
*/
|
|
1039
|
+
public setEquals(other: Iterable<T>): boolean;
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
/**
|
|
1043
|
+
* A list of elements that grows as it needs, read and written by position.
|
|
1044
|
+
*
|
|
1045
|
+
* @template T The type of the elements; not `undefined`, which means no element.
|
|
1046
|
+
*
|
|
1047
|
+
* @remarks
|
|
1048
|
+
* Reading or writing a position is O(1), adding at the end is amortized O(1),
|
|
1049
|
+
* and inserting or removing elsewhere moves the elements after it. Changing
|
|
1050
|
+
* the list while it is being enumerated makes the enumeration throw
|
|
1051
|
+
* `InvalidOperationException` at its next step.
|
|
1052
|
+
*
|
|
1053
|
+
* @example
|
|
1054
|
+
* ```ts
|
|
1055
|
+
* import { List } from "@noldova/context.collections";
|
|
1056
|
+
*
|
|
1057
|
+
* const names = new List(["Ana", "Mia"]);
|
|
1058
|
+
* names.add("Leo");
|
|
1059
|
+
* names.get(2); // "Leo"
|
|
1060
|
+
* names.tryGet(5); // undefined
|
|
1061
|
+
* names.insert(0, "Zoe");
|
|
1062
|
+
* names.sort();
|
|
1063
|
+
* names.toArray(); // ["Ana", "Mia", "Leo", "Zoe"]
|
|
1064
|
+
* ```
|
|
1065
|
+
*/
|
|
1066
|
+
export declare class List<T extends {} | null> extends Enumerable<T> implements IReadOnlyList<T> {
|
|
1067
|
+
/**
|
|
1068
|
+
* Creates a list of the given elements, copied.
|
|
1069
|
+
*/
|
|
1070
|
+
public constructor(items?: Iterable<T>);
|
|
1071
|
+
|
|
1072
|
+
/**
|
|
1073
|
+
* Starts an enumeration of the elements in order.
|
|
1074
|
+
*/
|
|
1075
|
+
public [Symbol.iterator](): Iterator<T>;
|
|
1076
|
+
|
|
1077
|
+
/**
|
|
1078
|
+
* The element at a zero-based position.
|
|
1079
|
+
*
|
|
1080
|
+
* @throws {ArgumentOutOfRangeException} When there is no element there,
|
|
1081
|
+
* including a negative or fractional position.
|
|
1082
|
+
*/
|
|
1083
|
+
public get(index: number): T;
|
|
1084
|
+
|
|
1085
|
+
/**
|
|
1086
|
+
* The element at a zero-based position; `undefined` when there is none.
|
|
1087
|
+
*/
|
|
1088
|
+
public tryGet(index: number): T | undefined;
|
|
1089
|
+
|
|
1090
|
+
/**
|
|
1091
|
+
* Replaces the element at a zero-based position.
|
|
1092
|
+
*
|
|
1093
|
+
* @throws {ArgumentOutOfRangeException} When there is no element there.
|
|
1094
|
+
*/
|
|
1095
|
+
public set(index: number, item: T): void;
|
|
1096
|
+
|
|
1097
|
+
/**
|
|
1098
|
+
* Adds an element at the end.
|
|
1099
|
+
*/
|
|
1100
|
+
public add(item: T): void;
|
|
1101
|
+
|
|
1102
|
+
/**
|
|
1103
|
+
* Adds elements at the end, in order. Adding the list to itself doubles it.
|
|
1104
|
+
*/
|
|
1105
|
+
public addRange(items: Iterable<T>): void;
|
|
1106
|
+
|
|
1107
|
+
/**
|
|
1108
|
+
* Inserts an element before a zero-based position; the list's length puts it at the end.
|
|
1109
|
+
*
|
|
1110
|
+
* @throws {ArgumentOutOfRangeException} When the position isn't an integer from
|
|
1111
|
+
* zero to the list's length.
|
|
1112
|
+
*/
|
|
1113
|
+
public insert(index: number, item: T): void;
|
|
1114
|
+
|
|
1115
|
+
/**
|
|
1116
|
+
* Inserts elements, in order, before a zero-based position.
|
|
1117
|
+
*
|
|
1118
|
+
* @throws {ArgumentOutOfRangeException} When the position isn't an integer from
|
|
1119
|
+
* zero to the list's length.
|
|
1120
|
+
*/
|
|
1121
|
+
public insertRange(index: number, items: Iterable<T>): void;
|
|
1122
|
+
|
|
1123
|
+
/**
|
|
1124
|
+
* Removes the first element equal to `item` by SameValueZero.
|
|
1125
|
+
*
|
|
1126
|
+
* @returns Whether an element was removed.
|
|
1127
|
+
*/
|
|
1128
|
+
public remove(item: T): boolean;
|
|
1129
|
+
|
|
1130
|
+
/**
|
|
1131
|
+
* Removes the element at a zero-based position.
|
|
1132
|
+
*
|
|
1133
|
+
* @throws {ArgumentOutOfRangeException} When there is no element there.
|
|
1134
|
+
*/
|
|
1135
|
+
public removeAt(index: number): void;
|
|
1136
|
+
|
|
1137
|
+
/**
|
|
1138
|
+
* Removes `count` elements from a zero-based position.
|
|
1139
|
+
*
|
|
1140
|
+
* @throws {ArgumentOutOfRangeException} When the position isn't an integer from
|
|
1141
|
+
* zero to the list's length, `count` isn't a non-negative integer, or the
|
|
1142
|
+
* range runs past the end.
|
|
1143
|
+
*/
|
|
1144
|
+
public removeRange(index: number, count: number): void;
|
|
1145
|
+
|
|
1146
|
+
/**
|
|
1147
|
+
* Removes every element that matches.
|
|
1148
|
+
*
|
|
1149
|
+
* @returns How many were removed.
|
|
1150
|
+
*/
|
|
1151
|
+
public removeAll(predicate: (item: T) => boolean): number;
|
|
1152
|
+
|
|
1153
|
+
/**
|
|
1154
|
+
* Removes every element.
|
|
1155
|
+
*/
|
|
1156
|
+
public clear(): void;
|
|
1157
|
+
|
|
1158
|
+
/**
|
|
1159
|
+
* The position of the first element equal to `item` by SameValueZero, or `-1`.
|
|
1160
|
+
*/
|
|
1161
|
+
public indexOf(item: T): number;
|
|
1162
|
+
|
|
1163
|
+
/**
|
|
1164
|
+
* The position of the last element equal to `item` by SameValueZero, or `-1`.
|
|
1165
|
+
*/
|
|
1166
|
+
public lastIndexOf(item: T): number;
|
|
1167
|
+
|
|
1168
|
+
/**
|
|
1169
|
+
* Sorts the list in place, keeping the order of equal elements. `orderBy`
|
|
1170
|
+
* is the deferred form that leaves the list as it is.
|
|
1171
|
+
*
|
|
1172
|
+
* @param comparison The order. Omitted, it is {@link Comparer.compare}.
|
|
1173
|
+
*/
|
|
1174
|
+
public sort(comparison?: Comparison<T>): void;
|
|
1175
|
+
|
|
1176
|
+
/**
|
|
1177
|
+
* Returns a view that reads this list, follows its changes and can't change it.
|
|
1178
|
+
*/
|
|
1179
|
+
public asReadOnly(): ReadOnlyList<T>;
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
/**
|
|
1183
|
+
* Values stored by key.
|
|
1184
|
+
*
|
|
1185
|
+
* @template TKey The type of the keys.
|
|
1186
|
+
* @template TValue The type of the values; not `undefined`, which means no value.
|
|
1187
|
+
*
|
|
1188
|
+
* @remarks
|
|
1189
|
+
* With the default equality, SameValueZero, lookups are O(1) on a native
|
|
1190
|
+
* `Map`; a custom {@link IEqualityComparer} hashes keys into buckets. The
|
|
1191
|
+
* dictionary enumerates its entries in the order their keys were added, which
|
|
1192
|
+
* replacing a value keeps. Changing it while it is being enumerated makes the
|
|
1193
|
+
* enumeration throw `InvalidOperationException` at its next step.
|
|
1194
|
+
*
|
|
1195
|
+
* @example
|
|
1196
|
+
* ```ts
|
|
1197
|
+
* import { Dictionary } from "@noldova/context.collections";
|
|
1198
|
+
*
|
|
1199
|
+
* const ages = new Dictionary<string, number>();
|
|
1200
|
+
* ages.add("Ana", 31);
|
|
1201
|
+
* ages.set("Ana", 32);
|
|
1202
|
+
* ages.get("Ana"); // 32
|
|
1203
|
+
* ages.tryGet("Mia"); // undefined
|
|
1204
|
+
* ages.get("Mia"); // throws KeyNotFoundException
|
|
1205
|
+
* for (const { key, value } of ages) console.log(key, value);
|
|
1206
|
+
* ```
|
|
1207
|
+
*/
|
|
1208
|
+
export declare class Dictionary<TKey, TValue extends {} | null> extends Enumerable<KeyValuePair<TKey, TValue>>
|
|
1209
|
+
implements IReadOnlyDictionary<TKey, TValue> {
|
|
1210
|
+
/**
|
|
1211
|
+
* Creates a dictionary of the given entries.
|
|
1212
|
+
*
|
|
1213
|
+
* @param entries The entries to add, in order.
|
|
1214
|
+
* @param comparer The key equality. Omitted, it is SameValueZero.
|
|
1215
|
+
* @throws {ArgumentException} When two entries have equal keys.
|
|
1216
|
+
*/
|
|
1217
|
+
public constructor(entries?: Iterable<KeyValuePair<TKey, TValue>>, comparer?: IEqualityComparer<TKey>);
|
|
1218
|
+
|
|
1219
|
+
/**
|
|
1220
|
+
* Starts an enumeration of the entries in the order their keys were added.
|
|
1221
|
+
*/
|
|
1222
|
+
public [Symbol.iterator](): Iterator<KeyValuePair<TKey, TValue>>;
|
|
1223
|
+
|
|
1224
|
+
/**
|
|
1225
|
+
* The value of a key.
|
|
1226
|
+
*
|
|
1227
|
+
* @throws {KeyNotFoundException} When the dictionary has no such key.
|
|
1228
|
+
*/
|
|
1229
|
+
public get(key: TKey): TValue;
|
|
1230
|
+
|
|
1231
|
+
/**
|
|
1232
|
+
* The value of a key; `undefined` when the dictionary has no such key.
|
|
1233
|
+
*/
|
|
1234
|
+
public tryGet(key: TKey): TValue | undefined;
|
|
1235
|
+
|
|
1236
|
+
/**
|
|
1237
|
+
* Adds a key with its value, or replaces the value of a key it has.
|
|
1238
|
+
*/
|
|
1239
|
+
public set(key: TKey, value: TValue): void;
|
|
1240
|
+
|
|
1241
|
+
/**
|
|
1242
|
+
* Adds a key with its value.
|
|
1243
|
+
*
|
|
1244
|
+
* @throws {ArgumentException} When the dictionary already has the key.
|
|
1245
|
+
*/
|
|
1246
|
+
public add(key: TKey, value: TValue): void;
|
|
1247
|
+
|
|
1248
|
+
/**
|
|
1249
|
+
* Adds a key with its value unless the dictionary already has the key.
|
|
1250
|
+
*
|
|
1251
|
+
* @returns Whether it was added.
|
|
1252
|
+
*/
|
|
1253
|
+
public tryAdd(key: TKey, value: TValue): boolean;
|
|
1254
|
+
|
|
1255
|
+
/**
|
|
1256
|
+
* Removes a key and its value.
|
|
1257
|
+
*
|
|
1258
|
+
* @returns Whether the key was there.
|
|
1259
|
+
*/
|
|
1260
|
+
public remove(key: TKey): boolean;
|
|
1261
|
+
|
|
1262
|
+
/**
|
|
1263
|
+
* Tells whether the dictionary has a key.
|
|
1264
|
+
*/
|
|
1265
|
+
public containsKey(key: TKey): boolean;
|
|
1266
|
+
|
|
1267
|
+
/**
|
|
1268
|
+
* Tells whether a value equals `value` by SameValueZero. It reads every value.
|
|
1269
|
+
*/
|
|
1270
|
+
public containsValue(value: TValue): boolean;
|
|
1271
|
+
|
|
1272
|
+
/**
|
|
1273
|
+
* The keys, in the order they were added; it follows later changes.
|
|
1274
|
+
*/
|
|
1275
|
+
public keys(): Enumerable<TKey>;
|
|
1276
|
+
|
|
1277
|
+
/**
|
|
1278
|
+
* The values, in their keys' order; it follows later changes.
|
|
1279
|
+
*/
|
|
1280
|
+
public values(): Enumerable<TValue>;
|
|
1281
|
+
|
|
1282
|
+
/**
|
|
1283
|
+
* Removes every entry.
|
|
1284
|
+
*/
|
|
1285
|
+
public clear(): void;
|
|
1286
|
+
|
|
1287
|
+
/**
|
|
1288
|
+
* Returns a view that reads this dictionary, follows its changes and can't change it.
|
|
1289
|
+
*/
|
|
1290
|
+
public asReadOnly(): ReadOnlyDictionary<TKey, TValue>;
|
|
1291
|
+
}
|
|
1292
|
+
|
|
1293
|
+
/**
|
|
1294
|
+
* A set of distinct elements.
|
|
1295
|
+
*
|
|
1296
|
+
* @template T The type of the elements.
|
|
1297
|
+
*
|
|
1298
|
+
* @remarks
|
|
1299
|
+
* Equality and speed are a {@link Dictionary}'s: O(1) on a native `Map` by
|
|
1300
|
+
* default, hashed buckets with a custom {@link IEqualityComparer}. The set
|
|
1301
|
+
* enumerates its elements in the order they were added. The `…With` methods
|
|
1302
|
+
* change this set; `union`, `intersect` and `except` return new sequences.
|
|
1303
|
+
*
|
|
1304
|
+
* @example
|
|
1305
|
+
* ```ts
|
|
1306
|
+
* import { HashSet } from "@noldova/context.collections";
|
|
1307
|
+
*
|
|
1308
|
+
* const tags = new HashSet(["a", "b"]);
|
|
1309
|
+
* tags.add("a"); // false: already there.
|
|
1310
|
+
* tags.unionWith(["c"]);
|
|
1311
|
+
* tags.isSupersetOf(["a", "c"]); // true
|
|
1312
|
+
* ```
|
|
1313
|
+
*/
|
|
1314
|
+
export declare class HashSet<T> extends Enumerable<T> implements IReadOnlySet<T> {
|
|
1315
|
+
/**
|
|
1316
|
+
* Creates a set of the given elements, keeping the first of equal ones.
|
|
1317
|
+
*
|
|
1318
|
+
* @param comparer The equality. Omitted, it is SameValueZero.
|
|
1319
|
+
*/
|
|
1320
|
+
public constructor(items?: Iterable<T>, comparer?: IEqualityComparer<T>);
|
|
1321
|
+
|
|
1322
|
+
/**
|
|
1323
|
+
* Starts an enumeration of the elements in the order they were added.
|
|
1324
|
+
*/
|
|
1325
|
+
public [Symbol.iterator](): Iterator<T>;
|
|
1326
|
+
|
|
1327
|
+
/**
|
|
1328
|
+
* Adds an element.
|
|
1329
|
+
*
|
|
1330
|
+
* @returns False when the set already holds an equal element, which stays.
|
|
1331
|
+
*/
|
|
1332
|
+
public add(item: T): boolean;
|
|
1333
|
+
|
|
1334
|
+
/**
|
|
1335
|
+
* Removes an element.
|
|
1336
|
+
*
|
|
1337
|
+
* @returns Whether it was there.
|
|
1338
|
+
*/
|
|
1339
|
+
public remove(item: T): boolean;
|
|
1340
|
+
|
|
1341
|
+
/**
|
|
1342
|
+
* Removes every element.
|
|
1343
|
+
*/
|
|
1344
|
+
public clear(): void;
|
|
1345
|
+
|
|
1346
|
+
/**
|
|
1347
|
+
* Adds every element of `other`.
|
|
1348
|
+
*/
|
|
1349
|
+
public unionWith(other: Iterable<T>): void;
|
|
1350
|
+
|
|
1351
|
+
/**
|
|
1352
|
+
* Keeps only the elements `other` also holds.
|
|
1353
|
+
*/
|
|
1354
|
+
public intersectWith(other: Iterable<T>): void;
|
|
1355
|
+
|
|
1356
|
+
/**
|
|
1357
|
+
* Removes every element `other` holds.
|
|
1358
|
+
*/
|
|
1359
|
+
public exceptWith(other: Iterable<T>): void;
|
|
1360
|
+
|
|
1361
|
+
/**
|
|
1362
|
+
* Keeps the elements that are in this set or `other` but not both.
|
|
1363
|
+
*/
|
|
1364
|
+
public symmetricExceptWith(other: Iterable<T>): void;
|
|
1365
|
+
|
|
1366
|
+
/**
|
|
1367
|
+
* Tells whether `other` holds every element of this set.
|
|
1368
|
+
*/
|
|
1369
|
+
public isSubsetOf(other: Iterable<T>): boolean;
|
|
1370
|
+
|
|
1371
|
+
/**
|
|
1372
|
+
* Tells whether this set holds every element of `other`.
|
|
1373
|
+
*/
|
|
1374
|
+
public isSupersetOf(other: Iterable<T>): boolean;
|
|
1375
|
+
|
|
1376
|
+
/**
|
|
1377
|
+
* Tells whether this set and `other` share an element.
|
|
1378
|
+
*/
|
|
1379
|
+
public overlaps(other: Iterable<T>): boolean;
|
|
1380
|
+
|
|
1381
|
+
/**
|
|
1382
|
+
* Tells whether this set and `other` hold the same elements, ignoring order and repeats.
|
|
1383
|
+
*/
|
|
1384
|
+
public setEquals(other: Iterable<T>): boolean;
|
|
1385
|
+
|
|
1386
|
+
/**
|
|
1387
|
+
* Returns a view that reads this set, follows its changes and can't change it.
|
|
1388
|
+
*/
|
|
1389
|
+
public asReadOnly(): ReadOnlySet<T>;
|
|
1390
|
+
}
|
|
1391
|
+
|
|
1392
|
+
/**
|
|
1393
|
+
* First in, first out.
|
|
1394
|
+
*
|
|
1395
|
+
* @template T The type of the elements; not `undefined`, which means no element.
|
|
1396
|
+
*
|
|
1397
|
+
* @remarks
|
|
1398
|
+
* Elements live in a ring buffer that doubles when full, so every operation is
|
|
1399
|
+
* O(1), amortized for `enqueue`. The queue enumerates from front to back.
|
|
1400
|
+
*
|
|
1401
|
+
* @example
|
|
1402
|
+
* ```ts
|
|
1403
|
+
* import { Queue } from "@noldova/context.collections";
|
|
1404
|
+
*
|
|
1405
|
+
* const jobs = new Queue(["a", "b"]);
|
|
1406
|
+
* jobs.enqueue("c");
|
|
1407
|
+
* jobs.dequeue(); // "a"
|
|
1408
|
+
* jobs.peek(); // "b"
|
|
1409
|
+
* ```
|
|
1410
|
+
*/
|
|
1411
|
+
export declare class Queue<T extends {} | null> extends Enumerable<T> {
|
|
1412
|
+
/**
|
|
1413
|
+
* Creates a queue of the given elements, the first at the front.
|
|
1414
|
+
*/
|
|
1415
|
+
public constructor(items?: Iterable<T>);
|
|
1416
|
+
|
|
1417
|
+
/**
|
|
1418
|
+
* Starts an enumeration of the elements from front to back.
|
|
1419
|
+
*/
|
|
1420
|
+
public [Symbol.iterator](): Iterator<T>;
|
|
1421
|
+
|
|
1422
|
+
/**
|
|
1423
|
+
* Adds an element at the back.
|
|
1424
|
+
*/
|
|
1425
|
+
public enqueue(item: T): void;
|
|
1426
|
+
|
|
1427
|
+
/**
|
|
1428
|
+
* Removes and returns the front element.
|
|
1429
|
+
*
|
|
1430
|
+
* @throws {InvalidOperationException} When the queue is empty.
|
|
1431
|
+
*/
|
|
1432
|
+
public dequeue(): T;
|
|
1433
|
+
|
|
1434
|
+
/**
|
|
1435
|
+
* Removes and returns the front element; `undefined` when the queue is empty.
|
|
1436
|
+
*/
|
|
1437
|
+
public tryDequeue(): T | undefined;
|
|
1438
|
+
|
|
1439
|
+
/**
|
|
1440
|
+
* Returns the front element without removing it.
|
|
1441
|
+
*
|
|
1442
|
+
* @throws {InvalidOperationException} When the queue is empty.
|
|
1443
|
+
*/
|
|
1444
|
+
public peek(): T;
|
|
1445
|
+
|
|
1446
|
+
/**
|
|
1447
|
+
* Returns the front element; `undefined` when the queue is empty.
|
|
1448
|
+
*/
|
|
1449
|
+
public tryPeek(): T | undefined;
|
|
1450
|
+
|
|
1451
|
+
/**
|
|
1452
|
+
* Removes every element.
|
|
1453
|
+
*/
|
|
1454
|
+
public clear(): void;
|
|
1455
|
+
}
|
|
1456
|
+
|
|
1457
|
+
/**
|
|
1458
|
+
* Last in, first out.
|
|
1459
|
+
*
|
|
1460
|
+
* @template T The type of the elements; not `undefined`, which means no element.
|
|
1461
|
+
*
|
|
1462
|
+
* @remarks
|
|
1463
|
+
* The stack enumerates from top to bottom, the order `pop` would return.
|
|
1464
|
+
*
|
|
1465
|
+
* @example
|
|
1466
|
+
* ```ts
|
|
1467
|
+
* import { Stack } from "@noldova/context.collections";
|
|
1468
|
+
*
|
|
1469
|
+
* const undo = new Stack(["type", "bold"]);
|
|
1470
|
+
* undo.push("delete");
|
|
1471
|
+
* undo.pop(); // "delete"
|
|
1472
|
+
* undo.toArray(); // ["bold", "type"]
|
|
1473
|
+
* ```
|
|
1474
|
+
*/
|
|
1475
|
+
export declare class Stack<T extends {} | null> extends Enumerable<T> {
|
|
1476
|
+
/**
|
|
1477
|
+
* Creates a stack of the given elements, pushed in order, so the last is on top.
|
|
1478
|
+
*/
|
|
1479
|
+
public constructor(items?: Iterable<T>);
|
|
1480
|
+
|
|
1481
|
+
/**
|
|
1482
|
+
* Starts an enumeration of the elements from top to bottom.
|
|
1483
|
+
*/
|
|
1484
|
+
public [Symbol.iterator](): Iterator<T>;
|
|
1485
|
+
|
|
1486
|
+
/**
|
|
1487
|
+
* Puts an element on top.
|
|
1488
|
+
*/
|
|
1489
|
+
public push(item: T): void;
|
|
1490
|
+
|
|
1491
|
+
/**
|
|
1492
|
+
* Removes and returns the top element.
|
|
1493
|
+
*
|
|
1494
|
+
* @throws {InvalidOperationException} When the stack is empty.
|
|
1495
|
+
*/
|
|
1496
|
+
public pop(): T;
|
|
1497
|
+
|
|
1498
|
+
/**
|
|
1499
|
+
* Removes and returns the top element; `undefined` when the stack is empty.
|
|
1500
|
+
*/
|
|
1501
|
+
public tryPop(): T | undefined;
|
|
1502
|
+
|
|
1503
|
+
/**
|
|
1504
|
+
* Returns the top element without removing it.
|
|
1505
|
+
*
|
|
1506
|
+
* @throws {InvalidOperationException} When the stack is empty.
|
|
1507
|
+
*/
|
|
1508
|
+
public peek(): T;
|
|
1509
|
+
|
|
1510
|
+
/**
|
|
1511
|
+
* Returns the top element; `undefined` when the stack is empty.
|
|
1512
|
+
*/
|
|
1513
|
+
public tryPeek(): T | undefined;
|
|
1514
|
+
|
|
1515
|
+
/**
|
|
1516
|
+
* Removes every element.
|
|
1517
|
+
*/
|
|
1518
|
+
public clear(): void;
|
|
1519
|
+
}
|