@byloth/core 2.0.0 → 2.0.1
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/dist/core.js +885 -182
- 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 +10 -9
- package/src/index.ts +1 -1
- package/src/models/aggregators/aggregated-async-iterator.ts +156 -1
- package/src/models/aggregators/aggregated-iterator.ts +141 -1
- package/src/models/aggregators/reduced-iterator.ts +130 -3
- package/src/models/callbacks/publisher.ts +21 -0
- package/src/models/callbacks/switchable-callback.ts +94 -21
- package/src/models/exceptions/core.ts +20 -0
- package/src/models/exceptions/index.ts +65 -0
- package/src/models/iterators/smart-async-iterator.ts +140 -0
- package/src/models/iterators/smart-iterator.ts +125 -0
- package/src/models/json/json-storage.ts +120 -0
- package/src/models/promises/deferred-promise.ts +10 -0
- package/src/models/promises/smart-promise.ts +40 -0
- package/src/models/promises/timed-promise.ts +5 -0
- package/src/models/timers/clock.ts +18 -0
- package/src/models/timers/countdown.ts +25 -0
- package/src/models/timers/game-loop.ts +23 -0
- package/src/utils/curve.ts +10 -0
- package/src/utils/random.ts +30 -0
|
@@ -43,10 +43,15 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
43
43
|
/**
|
|
44
44
|
* Initializes a new instance of the {@link AggregatedIterator} class.
|
|
45
45
|
*
|
|
46
|
+
* ---
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
46
49
|
* ```ts
|
|
47
50
|
* const iterator = new AggregatedIterator<string, number>([["A", 1], ["B", 2], ["A", 3], ["C", 4], ["B", 5]]);
|
|
48
51
|
* ```
|
|
49
52
|
*
|
|
53
|
+
* ---
|
|
54
|
+
*
|
|
50
55
|
* @param iterable The iterable to aggregate.
|
|
51
56
|
*/
|
|
52
57
|
public constructor(iterable: Iterable<[K, T]>);
|
|
@@ -54,6 +59,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
54
59
|
/**
|
|
55
60
|
* Initializes a new instance of the {@link AggregatedIterator} class.
|
|
56
61
|
*
|
|
62
|
+
* ---
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
57
65
|
* ```ts
|
|
58
66
|
* import { Random } from "@byloth/core";
|
|
59
67
|
*
|
|
@@ -69,6 +77,8 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
69
77
|
* });
|
|
70
78
|
* ```
|
|
71
79
|
*
|
|
80
|
+
* ---
|
|
81
|
+
*
|
|
72
82
|
* @param iterator The iterator to aggregate.
|
|
73
83
|
*/
|
|
74
84
|
public constructor(iterator: Iterator<[K, T]>);
|
|
@@ -76,6 +86,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
76
86
|
/**
|
|
77
87
|
* Initializes a new instance of the {@link AggregatedIterator} class.
|
|
78
88
|
*
|
|
89
|
+
* ---
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
79
92
|
* ```ts
|
|
80
93
|
* import { range, Random } from "@byloth/core";
|
|
81
94
|
*
|
|
@@ -88,6 +101,8 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
88
101
|
* });
|
|
89
102
|
* ```
|
|
90
103
|
*
|
|
104
|
+
* ---
|
|
105
|
+
*
|
|
91
106
|
* @param generatorFn The generator function to aggregate.
|
|
92
107
|
*/
|
|
93
108
|
public constructor(generatorFn: GeneratorFunction<[K, T]>);
|
|
@@ -95,10 +110,15 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
95
110
|
/**
|
|
96
111
|
* Initializes a new instance of the {@link AggregatedIterator} class.
|
|
97
112
|
*
|
|
113
|
+
* ---
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
98
116
|
* ```ts
|
|
99
117
|
* const iterator = new AggregatedIterator(keyedValues);
|
|
100
118
|
* ```
|
|
101
119
|
*
|
|
120
|
+
* ---
|
|
121
|
+
*
|
|
102
122
|
* @param argument The iterable, iterator or generator function to aggregate.
|
|
103
123
|
*/
|
|
104
124
|
public constructor(argument: IteratorLike<[K, T]> | GeneratorFunction<[K, T]>);
|
|
@@ -120,6 +140,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
120
140
|
* object that will contain all the boolean results for each group.
|
|
121
141
|
* If the iterator is infinite, the method will never return.
|
|
122
142
|
*
|
|
143
|
+
* ---
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
123
146
|
* ```ts
|
|
124
147
|
* const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
125
148
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -128,6 +151,8 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
128
151
|
* console.log(results.toObject()); // { odd: false, even: true }
|
|
129
152
|
* ```
|
|
130
153
|
*
|
|
154
|
+
* ---
|
|
155
|
+
*
|
|
131
156
|
* @param predicate The condition to check for each element of the iterator.
|
|
132
157
|
*
|
|
133
158
|
* @returns A new {@link ReducedIterator} containing the boolean results for each group.
|
|
@@ -164,6 +189,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
164
189
|
* object that will contain all the boolean results for each group.
|
|
165
190
|
* If the iterator is infinite, the method will never return.
|
|
166
191
|
*
|
|
192
|
+
* ---
|
|
193
|
+
*
|
|
194
|
+
* @example
|
|
167
195
|
* ```ts
|
|
168
196
|
* const results = new SmartIterator<number>([-5, -4, -3, -2, -1, 0])
|
|
169
197
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -172,6 +200,8 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
172
200
|
* console.log(results.toObject()); // { odd: false, even: true }
|
|
173
201
|
* ```
|
|
174
202
|
*
|
|
203
|
+
* ---
|
|
204
|
+
*
|
|
175
205
|
* @param predicate The condition to check for each element of the iterator.
|
|
176
206
|
*
|
|
177
207
|
* @returns A {@link ReducedIterator} containing the boolean results for each group.
|
|
@@ -208,6 +238,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
208
238
|
* This means that the original iterator won't be consumed until the
|
|
209
239
|
* new one is and that consuming one of them will consume the other as well.
|
|
210
240
|
*
|
|
241
|
+
* ---
|
|
242
|
+
*
|
|
243
|
+
* @example
|
|
211
244
|
* ```ts
|
|
212
245
|
* const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
213
246
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -216,6 +249,8 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
216
249
|
* console.log(results.toObject()); // { odd: [3, 5], even: [0, 2, 6, 8] }
|
|
217
250
|
* ```
|
|
218
251
|
*
|
|
252
|
+
* ---
|
|
253
|
+
*
|
|
219
254
|
* @param predicate The condition to check for each element of the iterator.
|
|
220
255
|
*
|
|
221
256
|
* @returns A new {@link AggregatedIterator} containing only the elements that satisfy the condition.
|
|
@@ -235,6 +270,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
235
270
|
* This means that the original iterator won't be consumed until the
|
|
236
271
|
* new one is and that consuming one of them will consume the other as well.
|
|
237
272
|
*
|
|
273
|
+
* ---
|
|
274
|
+
*
|
|
275
|
+
* @example
|
|
238
276
|
* ```ts
|
|
239
277
|
* const results = new SmartIterator<number | string>([-3, "-1", 0, "2", "3", 5, 6, "8"])
|
|
240
278
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -243,6 +281,8 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
243
281
|
* console.log(results.toObject()); // { odd: [-3, 5], even: [0, 6] }
|
|
244
282
|
* ```
|
|
245
283
|
*
|
|
284
|
+
* ---
|
|
285
|
+
*
|
|
246
286
|
* @template S
|
|
247
287
|
* The type of the elements that satisfy the condition.
|
|
248
288
|
* This allows the type-system to infer the correct type of the new iterator.
|
|
@@ -284,6 +324,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
284
324
|
* This means that the original iterator won't be consumed until the
|
|
285
325
|
* new one is and that consuming one of them will consume the other as well.
|
|
286
326
|
*
|
|
327
|
+
* ---
|
|
328
|
+
*
|
|
329
|
+
* @example
|
|
287
330
|
* ```ts
|
|
288
331
|
* const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
289
332
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -292,6 +335,8 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
292
335
|
* console.log(results.toObject()); // { odd: [3, 1, 3, 5], even: [0, 2, 6, 8] }
|
|
293
336
|
* ```
|
|
294
337
|
*
|
|
338
|
+
* ---
|
|
339
|
+
*
|
|
295
340
|
* @template V The type of the elements after the transformation.
|
|
296
341
|
*
|
|
297
342
|
* @param iteratee The transformation function to apply to each element of the iterator.
|
|
@@ -329,6 +374,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
329
374
|
* object that will contain all the reduced results for each group.
|
|
330
375
|
* If the iterator is infinite, the method will never return.
|
|
331
376
|
*
|
|
377
|
+
* ---
|
|
378
|
+
*
|
|
379
|
+
* @example
|
|
332
380
|
* ```ts
|
|
333
381
|
* const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
334
382
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -337,6 +385,8 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
337
385
|
* console.log(results.toObject()); // { odd: 4, even: 16 }
|
|
338
386
|
* ```
|
|
339
387
|
*
|
|
388
|
+
* ---
|
|
389
|
+
*
|
|
340
390
|
* @param reducer The reducer function to apply to each element of the iterator.
|
|
341
391
|
*
|
|
342
392
|
* @returns A new {@link ReducedIterator} containing the reduced results for each group.
|
|
@@ -357,6 +407,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
357
407
|
* object that will contain all the reduced results for each group.
|
|
358
408
|
* If the iterator is infinite, the method will never return.
|
|
359
409
|
*
|
|
410
|
+
* ---
|
|
411
|
+
*
|
|
412
|
+
* @example
|
|
360
413
|
* ```ts
|
|
361
414
|
* const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
362
415
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -365,6 +418,8 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
365
418
|
* console.log(results.toObject()); // { odd: 4, even: 16 }
|
|
366
419
|
* ```
|
|
367
420
|
*
|
|
421
|
+
* ---
|
|
422
|
+
*
|
|
368
423
|
* @template A The type of the accumulator value which will also be the type of the final result of the reduction.
|
|
369
424
|
*
|
|
370
425
|
* @param reducer The reducer function to apply to each element of the iterator.
|
|
@@ -388,6 +443,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
388
443
|
* object that will contain all the reduced results for each group.
|
|
389
444
|
* If the iterator is infinite, the method will never return.
|
|
390
445
|
*
|
|
446
|
+
* ---
|
|
447
|
+
*
|
|
448
|
+
* @example
|
|
391
449
|
* ```ts
|
|
392
450
|
* const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
393
451
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -396,6 +454,8 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
396
454
|
* console.log(results.toObject()); // { odd: { value: 4 }, even: { value: 16 } }
|
|
397
455
|
* ```
|
|
398
456
|
*
|
|
457
|
+
* ---
|
|
458
|
+
*
|
|
399
459
|
* @template A The type of the accumulator value which will also be the type of the final result of the reduction.
|
|
400
460
|
*
|
|
401
461
|
* @param reducer The reducer function to apply to each element of the iterator.
|
|
@@ -450,6 +510,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
450
510
|
* This means that the original iterator won't be consumed until the
|
|
451
511
|
* new one is and that consuming one of them will consume the other as well.
|
|
452
512
|
*
|
|
513
|
+
* ---
|
|
514
|
+
*
|
|
515
|
+
* @example
|
|
453
516
|
* ```ts
|
|
454
517
|
* const results = new SmartIterator<number[]>([[-3, -1], 0, 2, 3, 5, [6, 8]])
|
|
455
518
|
* .groupBy((values) =>
|
|
@@ -462,6 +525,8 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
462
525
|
* console.log(results.toObject()); // { odd: [-3, -1, 3, 5], even: [0, 2, 6, 8] }
|
|
463
526
|
* ```
|
|
464
527
|
*
|
|
528
|
+
* ---
|
|
529
|
+
*
|
|
465
530
|
* @template V The type of the elements after the transformation.
|
|
466
531
|
*
|
|
467
532
|
* @param iteratee The transformation function to apply to each element of the iterator.
|
|
@@ -503,6 +568,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
503
568
|
* This means that the original iterator won't be consumed until the
|
|
504
569
|
* new one is and that consuming one of them will consume the other as well.
|
|
505
570
|
*
|
|
571
|
+
* ---
|
|
572
|
+
*
|
|
573
|
+
* @example
|
|
506
574
|
* ```ts
|
|
507
575
|
* const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
508
576
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -511,6 +579,8 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
511
579
|
* console.log(results.toObject()); // { odd: [3, 5], even: [6, 8] }
|
|
512
580
|
* ```
|
|
513
581
|
*
|
|
582
|
+
* ---
|
|
583
|
+
*
|
|
514
584
|
* @param count The number of elements to drop from the beginning of each group.
|
|
515
585
|
*
|
|
516
586
|
* @returns A new {@link AggregatedIterator} containing the remaining elements.
|
|
@@ -549,6 +619,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
549
619
|
* This means that the original iterator won't be consumed until the
|
|
550
620
|
* new one is and that consuming one of them will consume the other as well.
|
|
551
621
|
*
|
|
622
|
+
* ---
|
|
623
|
+
*
|
|
624
|
+
* @example
|
|
552
625
|
* ```ts
|
|
553
626
|
* const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
554
627
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -557,7 +630,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
557
630
|
* console.log(results.toObject()); // { odd: [-3, -1], even: [0, 2] }
|
|
558
631
|
* ```
|
|
559
632
|
*
|
|
560
|
-
*
|
|
633
|
+
* ---
|
|
634
|
+
*
|
|
635
|
+
* @param limit The number of elements to take from the beginning of each group.
|
|
561
636
|
*
|
|
562
637
|
* @returns A new {@link AggregatedIterator} containing the taken elements.
|
|
563
638
|
*/
|
|
@@ -591,6 +666,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
591
666
|
* object that will contain the first element that satisfies the condition for each group.
|
|
592
667
|
* If the iterator is infinite, the method will never return.
|
|
593
668
|
*
|
|
669
|
+
* ---
|
|
670
|
+
*
|
|
671
|
+
* @example
|
|
594
672
|
* ```ts
|
|
595
673
|
* const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
596
674
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -599,6 +677,8 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
599
677
|
* console.log(results.toObject()); // { odd: 3, even: 2 }
|
|
600
678
|
* ```
|
|
601
679
|
*
|
|
680
|
+
* ---
|
|
681
|
+
*
|
|
602
682
|
* @param predicate The condition to check for each element of the iterator.
|
|
603
683
|
*
|
|
604
684
|
* @returns A new {@link ReducedIterator} containing the first element that satisfies the condition for each group.
|
|
@@ -617,6 +697,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
617
697
|
* object that will contain the first element that satisfies the condition for each group.
|
|
618
698
|
* If the iterator is infinite, the method will never return.
|
|
619
699
|
*
|
|
700
|
+
* ---
|
|
701
|
+
*
|
|
702
|
+
* @example
|
|
620
703
|
* ```ts
|
|
621
704
|
* const results = new SmartIterator<number | string>([-3, "-1", 0, "2", "3", 5, 6, "8"])
|
|
622
705
|
* .groupBy((value) => Number(value) % 2 === 0 ? "even" : "odd")
|
|
@@ -625,6 +708,8 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
625
708
|
* console.log(results.toObject()); // { odd: -3, even: 0 }
|
|
626
709
|
* ```
|
|
627
710
|
*
|
|
711
|
+
* ---
|
|
712
|
+
*
|
|
628
713
|
* @template S
|
|
629
714
|
* The type of the elements that satisfy the condition.
|
|
630
715
|
* This allows the type-system to infer the correct type of the new iterator.
|
|
@@ -667,6 +752,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
667
752
|
* This means that the original iterator won't be consumed until the
|
|
668
753
|
* new one is and that consuming one of them will consume the other as well.
|
|
669
754
|
*
|
|
755
|
+
* ---
|
|
756
|
+
*
|
|
757
|
+
* @example
|
|
670
758
|
* ```ts
|
|
671
759
|
* const results = new SmartIterator<number>([-3, 0, 2, -1, 3])
|
|
672
760
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -675,6 +763,8 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
675
763
|
* console.log(results.toObject()); // { odd: [[0, -3], [1, -1], [2, 3]], even: [[0, 0], [1, 2]] }
|
|
676
764
|
* ```
|
|
677
765
|
*
|
|
766
|
+
* ---
|
|
767
|
+
*
|
|
678
768
|
* @returns A new {@link AggregatedIterator} containing the enumerated elements.
|
|
679
769
|
*/
|
|
680
770
|
public enumerate(): AggregatedIterator<K, [number, T]>
|
|
@@ -693,6 +783,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
693
783
|
* This means that the original iterator won't be consumed until the
|
|
694
784
|
* new one is and that consuming one of them will consume the other as well.
|
|
695
785
|
*
|
|
786
|
+
* ---
|
|
787
|
+
*
|
|
788
|
+
* @example
|
|
696
789
|
* ```ts
|
|
697
790
|
* const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 6, -3, -1, 0, 5, 6, 8, 0, 2])
|
|
698
791
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -701,6 +794,8 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
701
794
|
* console.log(results.toObject()); // { odd: [-3, -1, 3, 5], even: [0, 2, 6, 8] }
|
|
702
795
|
* ```
|
|
703
796
|
*
|
|
797
|
+
* ---
|
|
798
|
+
*
|
|
704
799
|
* @returns A new {@link AggregatedIterator} containing only the unique elements.
|
|
705
800
|
*/
|
|
706
801
|
public unique(): AggregatedIterator<K, T>
|
|
@@ -729,6 +824,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
729
824
|
*
|
|
730
825
|
* If the iterator is infinite, the method will never return.
|
|
731
826
|
*
|
|
827
|
+
* ---
|
|
828
|
+
*
|
|
829
|
+
* @example
|
|
732
830
|
* ```ts
|
|
733
831
|
* const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
734
832
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -737,6 +835,8 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
737
835
|
* console.log(results.toObject()); // { odd: 4, even: 4 }
|
|
738
836
|
* ```
|
|
739
837
|
*
|
|
838
|
+
* ---
|
|
839
|
+
*
|
|
740
840
|
* @returns A new {@link ReducedIterator} containing the number of elements for each group.
|
|
741
841
|
*/
|
|
742
842
|
public count(): ReducedIterator<K, number>
|
|
@@ -763,6 +863,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
763
863
|
* This method will consume the entire iterator in the process.
|
|
764
864
|
* If the iterator is infinite, the method will never return.
|
|
765
865
|
*
|
|
866
|
+
* ---
|
|
867
|
+
*
|
|
868
|
+
* @example
|
|
766
869
|
* ```ts
|
|
767
870
|
* const aggregator = new SmartIterator<number>([-3, 0, 2, -1, 3])
|
|
768
871
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd");
|
|
@@ -773,6 +876,8 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
773
876
|
* };
|
|
774
877
|
* ```
|
|
775
878
|
*
|
|
879
|
+
* ---
|
|
880
|
+
*
|
|
776
881
|
* @param iteratee The function to execute for each element of the iterator.
|
|
777
882
|
*/
|
|
778
883
|
public forEach(iteratee: KeyedIteratee<K, T>): void
|
|
@@ -798,6 +903,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
798
903
|
* This means that the original iterator won't be consumed until the
|
|
799
904
|
* new one is and that consuming one of them will consume the other as well.
|
|
800
905
|
*
|
|
906
|
+
* ---
|
|
907
|
+
*
|
|
908
|
+
* @example
|
|
801
909
|
* ```ts
|
|
802
910
|
* const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
803
911
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -807,6 +915,8 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
807
915
|
* console.log(results.toObject()); // { "+": [1, 0, 3, 6], "-": [-3, -2, -5, -8] }
|
|
808
916
|
* ```
|
|
809
917
|
*
|
|
918
|
+
* ---
|
|
919
|
+
*
|
|
810
920
|
* @template J The type of the new key.
|
|
811
921
|
*
|
|
812
922
|
* @param iteratee The function to determine the new key for each element of the iterator.
|
|
@@ -841,6 +951,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
841
951
|
* This means that the original iterator won't be consumed until the
|
|
842
952
|
* new one is and that consuming one of them will consume the other as well.
|
|
843
953
|
*
|
|
954
|
+
* ---
|
|
955
|
+
*
|
|
956
|
+
* @example
|
|
844
957
|
* ```ts
|
|
845
958
|
* const keys = new SmartIterator([-3, Symbol(), "A", { }, null, [1 , 2, 3], false])
|
|
846
959
|
* .groupBy((value) => typeof value)
|
|
@@ -849,6 +962,8 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
849
962
|
* console.log(keys.toArray()); // ["number", "symbol", "string", "object", "boolean"]
|
|
850
963
|
* ```
|
|
851
964
|
*
|
|
965
|
+
* ---
|
|
966
|
+
*
|
|
852
967
|
* @returns A new {@link SmartIterator} containing all the keys of the iterator.
|
|
853
968
|
*/
|
|
854
969
|
public keys(): SmartIterator<K>
|
|
@@ -880,6 +995,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
880
995
|
* This means that the original iterator won't be consumed until the
|
|
881
996
|
* new one is and that consuming one of them will consume the other as well.
|
|
882
997
|
*
|
|
998
|
+
* ---
|
|
999
|
+
*
|
|
1000
|
+
* @example
|
|
883
1001
|
* ```ts
|
|
884
1002
|
* const entries = new SmartIterator<number>([-3, 0, 2, -1, 3])
|
|
885
1003
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -888,6 +1006,8 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
888
1006
|
* console.log(entries.toArray()); // [["odd", -3], ["even", 0], ["even", 2], ["odd", -1], ["odd", 3]]
|
|
889
1007
|
* ```
|
|
890
1008
|
*
|
|
1009
|
+
* ---
|
|
1010
|
+
*
|
|
891
1011
|
* @returns A new {@link SmartIterator} containing all the entries of the iterator.
|
|
892
1012
|
*/
|
|
893
1013
|
public entries(): SmartIterator<[K, T]>
|
|
@@ -906,6 +1026,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
906
1026
|
* This means that the original iterator won't be consumed until the
|
|
907
1027
|
* new one is and that consuming one of them will consume the other as well.
|
|
908
1028
|
*
|
|
1029
|
+
* ---
|
|
1030
|
+
*
|
|
1031
|
+
* @example
|
|
909
1032
|
* ```ts
|
|
910
1033
|
* const values = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
911
1034
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -914,6 +1037,8 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
914
1037
|
* console.log(values.toArray()); // [-3, -1, 0, 2, 3, 5, 6, 8]
|
|
915
1038
|
* ```
|
|
916
1039
|
*
|
|
1040
|
+
* ---
|
|
1041
|
+
*
|
|
917
1042
|
* @returns A new {@link SmartIterator} containing all the values of the iterator.
|
|
918
1043
|
*/
|
|
919
1044
|
public values(): SmartIterator<T>
|
|
@@ -932,6 +1057,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
932
1057
|
*
|
|
933
1058
|
* If the iterator is infinite, the method will never return.
|
|
934
1059
|
*
|
|
1060
|
+
* ---
|
|
1061
|
+
*
|
|
1062
|
+
* @example
|
|
935
1063
|
* ```ts
|
|
936
1064
|
* const aggregator = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
937
1065
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd");
|
|
@@ -939,6 +1067,8 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
939
1067
|
* console.log(aggregator.toArray()); // [[-3, -1, 3, 5], [0, 2, 6, 8]]
|
|
940
1068
|
* ```
|
|
941
1069
|
*
|
|
1070
|
+
* ---
|
|
1071
|
+
*
|
|
942
1072
|
* @returns An {@link Array} of arrays containing the elements of the iterator.
|
|
943
1073
|
*/
|
|
944
1074
|
public toArray(): T[][]
|
|
@@ -954,6 +1084,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
954
1084
|
*
|
|
955
1085
|
* If the iterator is infinite, the method will never return.
|
|
956
1086
|
*
|
|
1087
|
+
* ---
|
|
1088
|
+
*
|
|
1089
|
+
* @example
|
|
957
1090
|
* ```ts
|
|
958
1091
|
* const aggregator = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
959
1092
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd");
|
|
@@ -961,6 +1094,8 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
961
1094
|
* console.log(aggregator.toMap()); // Map(2) { "odd" => [-3, -1, 3, 5], "even" => [0, 2, 6, 8] }
|
|
962
1095
|
* ```
|
|
963
1096
|
*
|
|
1097
|
+
* ---
|
|
1098
|
+
*
|
|
964
1099
|
* @returns A {@link Map} containing the elements of the iterator.
|
|
965
1100
|
*/
|
|
966
1101
|
public toMap(): Map<K, T[]>
|
|
@@ -984,6 +1119,9 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
984
1119
|
*
|
|
985
1120
|
* If the iterator is infinite, the method will never return.
|
|
986
1121
|
*
|
|
1122
|
+
* ---
|
|
1123
|
+
*
|
|
1124
|
+
* @example
|
|
987
1125
|
* ```ts
|
|
988
1126
|
* const aggregator = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
989
1127
|
* .groupBy((value) => value % 2 === 0 ? "even" : "odd");
|
|
@@ -991,6 +1129,8 @@ export default class AggregatedIterator<K extends PropertyKey, T>
|
|
|
991
1129
|
* console.log(aggregator.toObject()); // { odd: [-3, -1, 3, 5], even: [0, 2, 6, 8] }
|
|
992
1130
|
* ```
|
|
993
1131
|
*
|
|
1132
|
+
* ---
|
|
1133
|
+
*
|
|
994
1134
|
* @returns An {@link Object} containing the elements of the iterator.
|
|
995
1135
|
*/
|
|
996
1136
|
public toObject(): Record<K, T[]>
|