@byloth/core 2.0.0 → 2.0.2
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 +1 -0
- package/dist/core.js +900 -187
- package/dist/core.js.map +1 -1
- package/dist/core.umd.cjs +2 -2
- package/dist/core.umd.cjs.map +1 -1
- package/package.json +13 -10
- package/src/core/types.ts +43 -10
- package/src/index.ts +3 -2
- package/src/models/aggregators/aggregated-async-iterator.ts +161 -1
- package/src/models/aggregators/aggregated-iterator.ts +146 -1
- package/src/models/aggregators/reduced-iterator.ts +148 -8
- package/src/models/aggregators/types.ts +35 -0
- package/src/models/callbacks/callable-object.ts +7 -0
- package/src/models/callbacks/publisher.ts +33 -8
- package/src/models/callbacks/switchable-callback.ts +102 -21
- package/src/models/callbacks/types.ts +32 -0
- package/src/models/exceptions/core.ts +29 -0
- package/src/models/exceptions/index.ts +105 -1
- package/src/models/iterators/smart-async-iterator.ts +145 -0
- package/src/models/iterators/smart-iterator.ts +130 -0
- package/src/models/iterators/types.ts +79 -1
- package/src/models/json/json-storage.ts +123 -0
- package/src/models/json/types.ts +1 -1
- package/src/models/promises/deferred-promise.ts +15 -0
- package/src/models/promises/smart-promise.ts +45 -0
- package/src/models/promises/timed-promise.ts +10 -0
- package/src/models/promises/types.ts +30 -0
- package/src/models/timers/clock.ts +21 -0
- package/src/models/timers/countdown.ts +30 -0
- package/src/models/timers/game-loop.ts +26 -0
- package/src/models/types.ts +1 -1
- package/src/utils/async.ts +15 -0
- package/src/utils/curve.ts +11 -1
- package/src/utils/date.ts +36 -6
- package/src/utils/dom.ts +5 -0
- package/src/utils/iterator.ts +40 -0
- package/src/utils/math.ts +15 -0
- package/src/utils/random.ts +34 -0
- package/src/utils/string.ts +5 -0
|
@@ -22,6 +22,9 @@ import type { KeyedIteratee, KeyedTypeGuardPredicate, KeyedReducer } from "./typ
|
|
|
22
22
|
* This is particularly useful when you need to group elements and
|
|
23
23
|
* then perform specific operations on the groups themselves.
|
|
24
24
|
*
|
|
25
|
+
* ---
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
25
28
|
* ```ts
|
|
26
29
|
* const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
27
30
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -30,6 +33,8 @@ import type { KeyedIteratee, KeyedTypeGuardPredicate, KeyedReducer } from "./typ
|
|
|
30
33
|
* console.log(results.toObject()); // { odd: 4, even: 4 }
|
|
31
34
|
* ```
|
|
32
35
|
*
|
|
36
|
+
* ---
|
|
37
|
+
*
|
|
33
38
|
* @template K The type of the keys used to group the elements.
|
|
34
39
|
* @template T The type of the elements to aggregate.
|
|
35
40
|
*/
|
|
@@ -43,10 +48,15 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
43
48
|
/**
|
|
44
49
|
* Initializes a new instance of the {@link AggregatedIterator} class.
|
|
45
50
|
*
|
|
51
|
+
* ---
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
46
54
|
* ```ts
|
|
47
55
|
* const iterator = new AggregatedIterator<string, number>([["A", 1], ["B", 2], ["A", 3], ["C", 4], ["B", 5]]);
|
|
48
56
|
* ```
|
|
49
57
|
*
|
|
58
|
+
* ---
|
|
59
|
+
*
|
|
50
60
|
* @param iterable The iterable to aggregate.
|
|
51
61
|
*/
|
|
52
62
|
public constructor(iterable: Iterable<[K, T]>);
|
|
@@ -54,6 +64,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
54
64
|
/**
|
|
55
65
|
* Initializes a new instance of the {@link AggregatedIterator} class.
|
|
56
66
|
*
|
|
67
|
+
* ---
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
57
70
|
* ```ts
|
|
58
71
|
* import { Random } from "@byloth/core";
|
|
59
72
|
*
|
|
@@ -69,6 +82,8 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
69
82
|
* });
|
|
70
83
|
* ```
|
|
71
84
|
*
|
|
85
|
+
* ---
|
|
86
|
+
*
|
|
72
87
|
* @param iterator The iterator to aggregate.
|
|
73
88
|
*/
|
|
74
89
|
public constructor(iterator: Iterator<[K, T]>);
|
|
@@ -76,6 +91,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
76
91
|
/**
|
|
77
92
|
* Initializes a new instance of the {@link AggregatedIterator} class.
|
|
78
93
|
*
|
|
94
|
+
* ---
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
79
97
|
* ```ts
|
|
80
98
|
* import { range, Random } from "@byloth/core";
|
|
81
99
|
*
|
|
@@ -88,6 +106,8 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
88
106
|
* });
|
|
89
107
|
* ```
|
|
90
108
|
*
|
|
109
|
+
* ---
|
|
110
|
+
*
|
|
91
111
|
* @param generatorFn The generator function to aggregate.
|
|
92
112
|
*/
|
|
93
113
|
public constructor(generatorFn: GeneratorFunction<[K, T]>);
|
|
@@ -95,10 +115,15 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
95
115
|
/**
|
|
96
116
|
* Initializes a new instance of the {@link AggregatedIterator} class.
|
|
97
117
|
*
|
|
118
|
+
* ---
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
98
121
|
* ```ts
|
|
99
122
|
* const iterator = new AggregatedIterator(keyedValues);
|
|
100
123
|
* ```
|
|
101
124
|
*
|
|
125
|
+
* ---
|
|
126
|
+
*
|
|
102
127
|
* @param argument The iterable, iterator or generator function to aggregate.
|
|
103
128
|
*/
|
|
104
129
|
public constructor(argument: IteratorLike<[K, T]> | GeneratorFunction<[K, T]>);
|
|
@@ -120,6 +145,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
120
145
|
* object that will contain all the boolean results for each group.
|
|
121
146
|
* If the iterator is infinite, the method will never return.
|
|
122
147
|
*
|
|
148
|
+
* ---
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
123
151
|
* ```ts
|
|
124
152
|
* const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
125
153
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -128,6 +156,8 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
128
156
|
* console.log(results.toObject()); // { odd: false, even: true }
|
|
129
157
|
* ```
|
|
130
158
|
*
|
|
159
|
+
* ---
|
|
160
|
+
*
|
|
131
161
|
* @param predicate The condition to check for each element of the iterator.
|
|
132
162
|
*
|
|
133
163
|
* @returns A new {@link ReducedIterator} containing the boolean results for each group.
|
|
@@ -164,6 +194,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
164
194
|
* object that will contain all the boolean results for each group.
|
|
165
195
|
* If the iterator is infinite, the method will never return.
|
|
166
196
|
*
|
|
197
|
+
* ---
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
167
200
|
* ```ts
|
|
168
201
|
* const results = new SmartIterator<number>([-5, -4, -3, -2, -1, 0])
|
|
169
202
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -172,6 +205,8 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
172
205
|
* console.log(results.toObject()); // { odd: false, even: true }
|
|
173
206
|
* ```
|
|
174
207
|
*
|
|
208
|
+
* ---
|
|
209
|
+
*
|
|
175
210
|
* @param predicate The condition to check for each element of the iterator.
|
|
176
211
|
*
|
|
177
212
|
* @returns A {@link ReducedIterator} containing the boolean results for each group.
|
|
@@ -208,6 +243,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
208
243
|
* This means that the original iterator won't be consumed until the
|
|
209
244
|
* new one is and that consuming one of them will consume the other as well.
|
|
210
245
|
*
|
|
246
|
+
* ---
|
|
247
|
+
*
|
|
248
|
+
* @example
|
|
211
249
|
* ```ts
|
|
212
250
|
* const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
213
251
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -216,6 +254,8 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
216
254
|
* console.log(results.toObject()); // { odd: [3, 5], even: [0, 2, 6, 8] }
|
|
217
255
|
* ```
|
|
218
256
|
*
|
|
257
|
+
* ---
|
|
258
|
+
*
|
|
219
259
|
* @param predicate The condition to check for each element of the iterator.
|
|
220
260
|
*
|
|
221
261
|
* @returns A new {@link AggregatedIterator} containing only the elements that satisfy the condition.
|
|
@@ -235,6 +275,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
235
275
|
* This means that the original iterator won't be consumed until the
|
|
236
276
|
* new one is and that consuming one of them will consume the other as well.
|
|
237
277
|
*
|
|
278
|
+
* ---
|
|
279
|
+
*
|
|
280
|
+
* @example
|
|
238
281
|
* ```ts
|
|
239
282
|
* const results = new SmartIterator<number | string>([-3, "-1", 0, "2", "3", 5, 6, "8"])
|
|
240
283
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -243,6 +286,8 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
243
286
|
* console.log(results.toObject()); // { odd: [-3, 5], even: [0, 6] }
|
|
244
287
|
* ```
|
|
245
288
|
*
|
|
289
|
+
* ---
|
|
290
|
+
*
|
|
246
291
|
* @template S
|
|
247
292
|
* The type of the elements that satisfy the condition.
|
|
248
293
|
* This allows the type-system to infer the correct type of the new iterator.
|
|
@@ -284,6 +329,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
284
329
|
* This means that the original iterator won't be consumed until the
|
|
285
330
|
* new one is and that consuming one of them will consume the other as well.
|
|
286
331
|
*
|
|
332
|
+
* ---
|
|
333
|
+
*
|
|
334
|
+
* @example
|
|
287
335
|
* ```ts
|
|
288
336
|
* const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
289
337
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -292,6 +340,8 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
292
340
|
* console.log(results.toObject()); // { odd: [3, 1, 3, 5], even: [0, 2, 6, 8] }
|
|
293
341
|
* ```
|
|
294
342
|
*
|
|
343
|
+
* ---
|
|
344
|
+
*
|
|
295
345
|
* @template V The type of the elements after the transformation.
|
|
296
346
|
*
|
|
297
347
|
* @param iteratee The transformation function to apply to each element of the iterator.
|
|
@@ -329,6 +379,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
329
379
|
* object that will contain all the reduced results for each group.
|
|
330
380
|
* If the iterator is infinite, the method will never return.
|
|
331
381
|
*
|
|
382
|
+
* ---
|
|
383
|
+
*
|
|
384
|
+
* @example
|
|
332
385
|
* ```ts
|
|
333
386
|
* const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
334
387
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -337,6 +390,8 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
337
390
|
* console.log(results.toObject()); // { odd: 4, even: 16 }
|
|
338
391
|
* ```
|
|
339
392
|
*
|
|
393
|
+
* ---
|
|
394
|
+
*
|
|
340
395
|
* @param reducer The reducer function to apply to each element of the iterator.
|
|
341
396
|
*
|
|
342
397
|
* @returns A new {@link ReducedIterator} containing the reduced results for each group.
|
|
@@ -357,6 +412,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
357
412
|
* object that will contain all the reduced results for each group.
|
|
358
413
|
* If the iterator is infinite, the method will never return.
|
|
359
414
|
*
|
|
415
|
+
* ---
|
|
416
|
+
*
|
|
417
|
+
* @example
|
|
360
418
|
* ```ts
|
|
361
419
|
* const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
362
420
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -365,6 +423,8 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
365
423
|
* console.log(results.toObject()); // { odd: 4, even: 16 }
|
|
366
424
|
* ```
|
|
367
425
|
*
|
|
426
|
+
* ---
|
|
427
|
+
*
|
|
368
428
|
* @template A The type of the accumulator value which will also be the type of the final result of the reduction.
|
|
369
429
|
*
|
|
370
430
|
* @param reducer The reducer function to apply to each element of the iterator.
|
|
@@ -388,6 +448,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
388
448
|
* object that will contain all the reduced results for each group.
|
|
389
449
|
* If the iterator is infinite, the method will never return.
|
|
390
450
|
*
|
|
451
|
+
* ---
|
|
452
|
+
*
|
|
453
|
+
* @example
|
|
391
454
|
* ```ts
|
|
392
455
|
* const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
393
456
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -396,6 +459,8 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
396
459
|
* console.log(results.toObject()); // { odd: { value: 4 }, even: { value: 16 } }
|
|
397
460
|
* ```
|
|
398
461
|
*
|
|
462
|
+
* ---
|
|
463
|
+
*
|
|
399
464
|
* @template A The type of the accumulator value which will also be the type of the final result of the reduction.
|
|
400
465
|
*
|
|
401
466
|
* @param reducer The reducer function to apply to each element of the iterator.
|
|
@@ -450,6 +515,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
450
515
|
* This means that the original iterator won't be consumed until the
|
|
451
516
|
* new one is and that consuming one of them will consume the other as well.
|
|
452
517
|
*
|
|
518
|
+
* ---
|
|
519
|
+
*
|
|
520
|
+
* @example
|
|
453
521
|
* ```ts
|
|
454
522
|
* const results = new SmartIterator<number[]>([[-3, -1], 0, 2, 3, 5, [6, 8]])
|
|
455
523
|
* .groupBy((values) =>
|
|
@@ -462,6 +530,8 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
462
530
|
* console.log(results.toObject()); // { odd: [-3, -1, 3, 5], even: [0, 2, 6, 8] }
|
|
463
531
|
* ```
|
|
464
532
|
*
|
|
533
|
+
* ---
|
|
534
|
+
*
|
|
465
535
|
* @template V The type of the elements after the transformation.
|
|
466
536
|
*
|
|
467
537
|
* @param iteratee The transformation function to apply to each element of the iterator.
|
|
@@ -503,6 +573,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
503
573
|
* This means that the original iterator won't be consumed until the
|
|
504
574
|
* new one is and that consuming one of them will consume the other as well.
|
|
505
575
|
*
|
|
576
|
+
* ---
|
|
577
|
+
*
|
|
578
|
+
* @example
|
|
506
579
|
* ```ts
|
|
507
580
|
* const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
508
581
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -511,6 +584,8 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
511
584
|
* console.log(results.toObject()); // { odd: [3, 5], even: [6, 8] }
|
|
512
585
|
* ```
|
|
513
586
|
*
|
|
587
|
+
* ---
|
|
588
|
+
*
|
|
514
589
|
* @param count The number of elements to drop from the beginning of each group.
|
|
515
590
|
*
|
|
516
591
|
* @returns A new {@link AggregatedIterator} containing the remaining elements.
|
|
@@ -549,6 +624,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
549
624
|
* This means that the original iterator won't be consumed until the
|
|
550
625
|
* new one is and that consuming one of them will consume the other as well.
|
|
551
626
|
*
|
|
627
|
+
* ---
|
|
628
|
+
*
|
|
629
|
+
* @example
|
|
552
630
|
* ```ts
|
|
553
631
|
* const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
554
632
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -557,7 +635,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
557
635
|
* console.log(results.toObject()); // { odd: [-3, -1], even: [0, 2] }
|
|
558
636
|
* ```
|
|
559
637
|
*
|
|
560
|
-
*
|
|
638
|
+
* ---
|
|
639
|
+
*
|
|
640
|
+
* @param limit The number of elements to take from the beginning of each group.
|
|
561
641
|
*
|
|
562
642
|
* @returns A new {@link AggregatedIterator} containing the taken elements.
|
|
563
643
|
*/
|
|
@@ -591,6 +671,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
591
671
|
* object that will contain the first element that satisfies the condition for each group.
|
|
592
672
|
* If the iterator is infinite, the method will never return.
|
|
593
673
|
*
|
|
674
|
+
* ---
|
|
675
|
+
*
|
|
676
|
+
* @example
|
|
594
677
|
* ```ts
|
|
595
678
|
* const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
596
679
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -599,6 +682,8 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
599
682
|
* console.log(results.toObject()); // { odd: 3, even: 2 }
|
|
600
683
|
* ```
|
|
601
684
|
*
|
|
685
|
+
* ---
|
|
686
|
+
*
|
|
602
687
|
* @param predicate The condition to check for each element of the iterator.
|
|
603
688
|
*
|
|
604
689
|
* @returns A new {@link ReducedIterator} containing the first element that satisfies the condition for each group.
|
|
@@ -617,6 +702,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
617
702
|
* object that will contain the first element that satisfies the condition for each group.
|
|
618
703
|
* If the iterator is infinite, the method will never return.
|
|
619
704
|
*
|
|
705
|
+
* ---
|
|
706
|
+
*
|
|
707
|
+
* @example
|
|
620
708
|
* ```ts
|
|
621
709
|
* const results = new SmartIterator<number | string>([-3, "-1", 0, "2", "3", 5, 6, "8"])
|
|
622
710
|
* .groupBy((value) => Number(value) % 2 === 0 ? "even" : "odd")
|
|
@@ -625,6 +713,8 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
625
713
|
* console.log(results.toObject()); // { odd: -3, even: 0 }
|
|
626
714
|
* ```
|
|
627
715
|
*
|
|
716
|
+
* ---
|
|
717
|
+
*
|
|
628
718
|
* @template S
|
|
629
719
|
* The type of the elements that satisfy the condition.
|
|
630
720
|
* This allows the type-system to infer the correct type of the new iterator.
|
|
@@ -667,6 +757,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
667
757
|
* This means that the original iterator won't be consumed until the
|
|
668
758
|
* new one is and that consuming one of them will consume the other as well.
|
|
669
759
|
*
|
|
760
|
+
* ---
|
|
761
|
+
*
|
|
762
|
+
* @example
|
|
670
763
|
* ```ts
|
|
671
764
|
* const results = new SmartIterator<number>([-3, 0, 2, -1, 3])
|
|
672
765
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -675,6 +768,8 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
675
768
|
* console.log(results.toObject()); // { odd: [[0, -3], [1, -1], [2, 3]], even: [[0, 0], [1, 2]] }
|
|
676
769
|
* ```
|
|
677
770
|
*
|
|
771
|
+
* ---
|
|
772
|
+
*
|
|
678
773
|
* @returns A new {@link AggregatedIterator} containing the enumerated elements.
|
|
679
774
|
*/
|
|
680
775
|
public enumerate(): AggregatedIterator<K, [number, T]>
|
|
@@ -693,6 +788,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
693
788
|
* This means that the original iterator won't be consumed until the
|
|
694
789
|
* new one is and that consuming one of them will consume the other as well.
|
|
695
790
|
*
|
|
791
|
+
* ---
|
|
792
|
+
*
|
|
793
|
+
* @example
|
|
696
794
|
* ```ts
|
|
697
795
|
* const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 6, -3, -1, 0, 5, 6, 8, 0, 2])
|
|
698
796
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -701,6 +799,8 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
701
799
|
* console.log(results.toObject()); // { odd: [-3, -1, 3, 5], even: [0, 2, 6, 8] }
|
|
702
800
|
* ```
|
|
703
801
|
*
|
|
802
|
+
* ---
|
|
803
|
+
*
|
|
704
804
|
* @returns A new {@link AggregatedIterator} containing only the unique elements.
|
|
705
805
|
*/
|
|
706
806
|
public unique(): AggregatedIterator<K, T>
|
|
@@ -729,6 +829,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
729
829
|
*
|
|
730
830
|
* If the iterator is infinite, the method will never return.
|
|
731
831
|
*
|
|
832
|
+
* ---
|
|
833
|
+
*
|
|
834
|
+
* @example
|
|
732
835
|
* ```ts
|
|
733
836
|
* const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
734
837
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -737,6 +840,8 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
737
840
|
* console.log(results.toObject()); // { odd: 4, even: 4 }
|
|
738
841
|
* ```
|
|
739
842
|
*
|
|
843
|
+
* ---
|
|
844
|
+
*
|
|
740
845
|
* @returns A new {@link ReducedIterator} containing the number of elements for each group.
|
|
741
846
|
*/
|
|
742
847
|
public count(): ReducedIterator<K, number>
|
|
@@ -763,6 +868,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
763
868
|
* This method will consume the entire iterator in the process.
|
|
764
869
|
* If the iterator is infinite, the method will never return.
|
|
765
870
|
*
|
|
871
|
+
* ---
|
|
872
|
+
*
|
|
873
|
+
* @example
|
|
766
874
|
* ```ts
|
|
767
875
|
* const aggregator = new SmartIterator<number>([-3, 0, 2, -1, 3])
|
|
768
876
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd");
|
|
@@ -773,6 +881,8 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
773
881
|
* };
|
|
774
882
|
* ```
|
|
775
883
|
*
|
|
884
|
+
* ---
|
|
885
|
+
*
|
|
776
886
|
* @param iteratee The function to execute for each element of the iterator.
|
|
777
887
|
*/
|
|
778
888
|
public forEach(iteratee: KeyedIteratee<K, T>): void
|
|
@@ -798,6 +908,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
798
908
|
* This means that the original iterator won't be consumed until the
|
|
799
909
|
* new one is and that consuming one of them will consume the other as well.
|
|
800
910
|
*
|
|
911
|
+
* ---
|
|
912
|
+
*
|
|
913
|
+
* @example
|
|
801
914
|
* ```ts
|
|
802
915
|
* const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
803
916
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -807,6 +920,8 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
807
920
|
* console.log(results.toObject()); // { "+": [1, 0, 3, 6], "-": [-3, -2, -5, -8] }
|
|
808
921
|
* ```
|
|
809
922
|
*
|
|
923
|
+
* ---
|
|
924
|
+
*
|
|
810
925
|
* @template J The type of the new key.
|
|
811
926
|
*
|
|
812
927
|
* @param iteratee The function to determine the new key for each element of the iterator.
|
|
@@ -841,6 +956,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
841
956
|
* This means that the original iterator won't be consumed until the
|
|
842
957
|
* new one is and that consuming one of them will consume the other as well.
|
|
843
958
|
*
|
|
959
|
+
* ---
|
|
960
|
+
*
|
|
961
|
+
* @example
|
|
844
962
|
* ```ts
|
|
845
963
|
* const keys = new SmartIterator([-3, Symbol(), "A", { }, null, [1 , 2, 3], false])
|
|
846
964
|
* .groupBy((value) => typeof value)
|
|
@@ -849,6 +967,8 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
849
967
|
* console.log(keys.toArray()); // ["number", "symbol", "string", "object", "boolean"]
|
|
850
968
|
* ```
|
|
851
969
|
*
|
|
970
|
+
* ---
|
|
971
|
+
*
|
|
852
972
|
* @returns A new {@link SmartIterator} containing all the keys of the iterator.
|
|
853
973
|
*/
|
|
854
974
|
public keys(): SmartIterator<K>
|
|
@@ -880,6 +1000,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
880
1000
|
* This means that the original iterator won't be consumed until the
|
|
881
1001
|
* new one is and that consuming one of them will consume the other as well.
|
|
882
1002
|
*
|
|
1003
|
+
* ---
|
|
1004
|
+
*
|
|
1005
|
+
* @example
|
|
883
1006
|
* ```ts
|
|
884
1007
|
* const entries = new SmartIterator<number>([-3, 0, 2, -1, 3])
|
|
885
1008
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -888,6 +1011,8 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
888
1011
|
* console.log(entries.toArray()); // [["odd", -3], ["even", 0], ["even", 2], ["odd", -1], ["odd", 3]]
|
|
889
1012
|
* ```
|
|
890
1013
|
*
|
|
1014
|
+
* ---
|
|
1015
|
+
*
|
|
891
1016
|
* @returns A new {@link SmartIterator} containing all the entries of the iterator.
|
|
892
1017
|
*/
|
|
893
1018
|
public entries(): SmartIterator<[K, T]>
|
|
@@ -906,6 +1031,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
906
1031
|
* This means that the original iterator won't be consumed until the
|
|
907
1032
|
* new one is and that consuming one of them will consume the other as well.
|
|
908
1033
|
*
|
|
1034
|
+
* ---
|
|
1035
|
+
*
|
|
1036
|
+
* @example
|
|
909
1037
|
* ```ts
|
|
910
1038
|
* const values = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
911
1039
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -914,6 +1042,8 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
914
1042
|
* console.log(values.toArray()); // [-3, -1, 0, 2, 3, 5, 6, 8]
|
|
915
1043
|
* ```
|
|
916
1044
|
*
|
|
1045
|
+
* ---
|
|
1046
|
+
*
|
|
917
1047
|
* @returns A new {@link SmartIterator} containing all the values of the iterator.
|
|
918
1048
|
*/
|
|
919
1049
|
public values(): SmartIterator<T>
|
|
@@ -932,6 +1062,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
932
1062
|
*
|
|
933
1063
|
* If the iterator is infinite, the method will never return.
|
|
934
1064
|
*
|
|
1065
|
+
* ---
|
|
1066
|
+
*
|
|
1067
|
+
* @example
|
|
935
1068
|
* ```ts
|
|
936
1069
|
* const aggregator = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
937
1070
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd");
|
|
@@ -939,6 +1072,8 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
939
1072
|
* console.log(aggregator.toArray()); // [[-3, -1, 3, 5], [0, 2, 6, 8]]
|
|
940
1073
|
* ```
|
|
941
1074
|
*
|
|
1075
|
+
* ---
|
|
1076
|
+
*
|
|
942
1077
|
* @returns An {@link Array} of arrays containing the elements of the iterator.
|
|
943
1078
|
*/
|
|
944
1079
|
public toArray(): T[][]
|
|
@@ -954,6 +1089,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
954
1089
|
*
|
|
955
1090
|
* If the iterator is infinite, the method will never return.
|
|
956
1091
|
*
|
|
1092
|
+
* ---
|
|
1093
|
+
*
|
|
1094
|
+
* @example
|
|
957
1095
|
* ```ts
|
|
958
1096
|
* const aggregator = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
959
1097
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd");
|
|
@@ -961,6 +1099,8 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
961
1099
|
* console.log(aggregator.toMap()); // Map(2) { "odd" => [-3, -1, 3, 5], "even" => [0, 2, 6, 8] }
|
|
962
1100
|
* ```
|
|
963
1101
|
*
|
|
1102
|
+
* ---
|
|
1103
|
+
*
|
|
964
1104
|
* @returns A {@link Map} containing the elements of the iterator.
|
|
965
1105
|
*/
|
|
966
1106
|
public toMap(): Map<K, T[]>
|
|
@@ -984,6 +1124,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
984
1124
|
*
|
|
985
1125
|
* If the iterator is infinite, the method will never return.
|
|
986
1126
|
*
|
|
1127
|
+
* ---
|
|
1128
|
+
*
|
|
1129
|
+
* @example
|
|
987
1130
|
* ```ts
|
|
988
1131
|
* const aggregator = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
989
1132
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd");
|
|
@@ -991,6 +1134,8 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
991
1134
|
* console.log(aggregator.toObject()); // { odd: [-3, -1, 3, 5], even: [0, 2, 6, 8] }
|
|
992
1135
|
* ```
|
|
993
1136
|
*
|
|
1137
|
+
* ---
|
|
1138
|
+
*
|
|
994
1139
|
* @returns An {@link Object} containing the elements of the iterator.
|
|
995
1140
|
*/
|
|
996
1141
|
public toObject(): Record<K, T[]>
|