@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.
Files changed (39) hide show
  1. package/README.md +1 -0
  2. package/dist/core.js +900 -187
  3. package/dist/core.js.map +1 -1
  4. package/dist/core.umd.cjs +2 -2
  5. package/dist/core.umd.cjs.map +1 -1
  6. package/package.json +13 -10
  7. package/src/core/types.ts +43 -10
  8. package/src/index.ts +3 -2
  9. package/src/models/aggregators/aggregated-async-iterator.ts +161 -1
  10. package/src/models/aggregators/aggregated-iterator.ts +146 -1
  11. package/src/models/aggregators/reduced-iterator.ts +148 -8
  12. package/src/models/aggregators/types.ts +35 -0
  13. package/src/models/callbacks/callable-object.ts +7 -0
  14. package/src/models/callbacks/publisher.ts +33 -8
  15. package/src/models/callbacks/switchable-callback.ts +102 -21
  16. package/src/models/callbacks/types.ts +32 -0
  17. package/src/models/exceptions/core.ts +29 -0
  18. package/src/models/exceptions/index.ts +105 -1
  19. package/src/models/iterators/smart-async-iterator.ts +145 -0
  20. package/src/models/iterators/smart-iterator.ts +130 -0
  21. package/src/models/iterators/types.ts +79 -1
  22. package/src/models/json/json-storage.ts +123 -0
  23. package/src/models/json/types.ts +1 -1
  24. package/src/models/promises/deferred-promise.ts +15 -0
  25. package/src/models/promises/smart-promise.ts +45 -0
  26. package/src/models/promises/timed-promise.ts +10 -0
  27. package/src/models/promises/types.ts +30 -0
  28. package/src/models/timers/clock.ts +21 -0
  29. package/src/models/timers/countdown.ts +30 -0
  30. package/src/models/timers/game-loop.ts +26 -0
  31. package/src/models/types.ts +1 -1
  32. package/src/utils/async.ts +15 -0
  33. package/src/utils/curve.ts +11 -1
  34. package/src/utils/date.ts +36 -6
  35. package/src/utils/dom.ts +5 -0
  36. package/src/utils/iterator.ts +40 -0
  37. package/src/utils/math.ts +15 -0
  38. package/src/utils/random.ts +34 -0
  39. package/src/utils/string.ts +5 -0
@@ -30,6 +30,9 @@ import type { MaybeAsyncKeyedIteratee, MaybeAsyncKeyedReducer } from "./types.js
30
30
  * This is particularly useful when you need to group elements and
31
31
  * then perform specific operations on the groups themselves.
32
32
  *
33
+ * ---
34
+ *
35
+ * @example
33
36
  * ```ts
34
37
  * const elements = fetch([...]); // Promise<[-3, -1, 0, 2, 3, 5, 6, 8]>;
35
38
  * const results = new SmartAsyncIterator(elements)
@@ -39,6 +42,8 @@ import type { MaybeAsyncKeyedIteratee, MaybeAsyncKeyedReducer } from "./types.js
39
42
  * console.log(await results.toObject()); // { odd: 4, even: 4 }
40
43
  * ```
41
44
  *
45
+ * ---
46
+ *
42
47
  * @template K The type of the keys used to group the elements.
43
48
  * @template T The type of the elements to aggregate.
44
49
  */
@@ -52,10 +57,15 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
52
57
  /**
53
58
  * Initializes a new instance of the {@link AggregatedAsyncIterator} class.
54
59
  *
60
+ * ---
61
+ *
62
+ * @example
55
63
  * ```ts
56
64
  * const iterator = new AggregatedAsyncIterator<string, number>([["A", 1], ["B", 2], ["A", 3], ["C", 4], ["B", 5]]);
57
65
  * ```
58
66
  *
67
+ * ---
68
+ *
59
69
  * @param iterable The iterable to aggregate.
60
70
  */
61
71
  public constructor(iterable: Iterable<[K, T]>);
@@ -63,11 +73,16 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
63
73
  /**
64
74
  * Initializes a new instance of the {@link AggregatedAsyncIterator} class.
65
75
  *
76
+ * ---
77
+ *
78
+ * @example
66
79
  * ```ts
67
80
  * const elements = fetch([...]); // Promise<[["A", 1], ["B", 2], ["A", 3], ["C", 4], ["B", 5]]>
68
81
  * const iterator = new AggregatedAsyncIterator<string, number>(elements);
69
82
  * ```
70
83
  *
84
+ * ---
85
+ *
71
86
  * @param iterable The iterable to aggregate.
72
87
  */
73
88
  public constructor(iterable: AsyncIterable<[K, T]>);
@@ -75,6 +90,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
75
90
  /**
76
91
  * Initializes a new instance of the {@link AggregatedAsyncIterator} class.
77
92
  *
93
+ * ---
94
+ *
95
+ * @example
78
96
  * ```ts
79
97
  * import { Random } from "@byloth/core";
80
98
  *
@@ -90,6 +108,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
90
108
  * });
91
109
  * ```
92
110
  *
111
+ * ---
112
+ *
93
113
  * @param iterator The iterator to aggregate.
94
114
  */
95
115
  public constructor(iterator: Iterator<[K, T]>);
@@ -97,6 +117,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
97
117
  /**
98
118
  * Initializes a new instance of the {@link AggregatedAsyncIterator} class.
99
119
  *
120
+ * ---
121
+ *
122
+ * @example
100
123
  * ```ts
101
124
  * import { Random } from "@byloth/core";
102
125
  *
@@ -112,6 +135,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
112
135
  * });
113
136
  * ```
114
137
  *
138
+ * ---
139
+ *
115
140
  * @param iterator The iterator to aggregate.
116
141
  */
117
142
  public constructor(iterator: AsyncIterator<[K, T]>);
@@ -119,6 +144,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
119
144
  /**
120
145
  * Initializes a new instance of the {@link AggregatedAsyncIterator} class.
121
146
  *
147
+ * ---
148
+ *
149
+ * @example
122
150
  * ```ts
123
151
  * import { range, Random } from "@byloth/core";
124
152
  *
@@ -131,6 +159,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
131
159
  * });
132
160
  * ```
133
161
  *
162
+ * ---
163
+ *
134
164
  * @param generatorFn The generator function to aggregate.
135
165
  */
136
166
  public constructor(generatorFn: GeneratorFunction<[K, T]>);
@@ -138,6 +168,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
138
168
  /**
139
169
  * Initializes a new instance of the {@link AggregatedAsyncIterator} class.
140
170
  *
171
+ * ---
172
+ *
173
+ * @example
141
174
  * ```ts
142
175
  * import { range, Random } from "@byloth/core";
143
176
  *
@@ -150,6 +183,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
150
183
  * });
151
184
  * ```
152
185
  *
186
+ * ---
187
+ *
153
188
  * @param generatorFn The generator function to aggregate.
154
189
  */
155
190
  public constructor(generatorFn: AsyncGeneratorFunction<[K, T]>);
@@ -157,10 +192,15 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
157
192
  /**
158
193
  * Initializes a new instance of the {@link AggregatedAsyncIterator} class.
159
194
  *
195
+ * ---
196
+ *
197
+ * @example
160
198
  * ```ts
161
199
  * const iterator = new AggregatedAsyncIterator(asyncKeyedValues);
162
200
  * ```
163
201
  *
202
+ * ---
203
+ *
164
204
  * @param argument The iterable, iterator or generator function to aggregate.
165
205
  */
166
206
  public constructor(argument: MaybeAsyncIteratorLike<[K, T]> | MaybeAsyncGeneratorFunction<[K, T]>);
@@ -182,6 +222,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
182
222
  * object that will contain all the boolean results for each group.
183
223
  * If the iterator is infinite, the method will never return.
184
224
  *
225
+ * ---
226
+ *
227
+ * @example
185
228
  * ```ts
186
229
  * const results = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
187
230
  * .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
@@ -190,6 +233,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
190
233
  * console.log(await results.toObject()); // { odd: false, even: true }
191
234
  * ```
192
235
  *
236
+ * ---
237
+ *
193
238
  * @param predicate The condition to check for each element of the iterator.
194
239
  *
195
240
  * @returns
@@ -227,6 +272,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
227
272
  * object that will contain all the boolean results for each group.
228
273
  * If the iterator is infinite, the method will never return.
229
274
  *
275
+ * ---
276
+ *
277
+ * @example
230
278
  * ```ts
231
279
  * const results = new SmartAsyncIterator<number>([-5, -4, -3, -2, -1, 0])
232
280
  * .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
@@ -235,6 +283,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
235
283
  * console.log(await results.toObject()); // { odd: false, even: true }
236
284
  * ```
237
285
  *
286
+ * ---
287
+ *
238
288
  * @param predicate The condition to check for each element of the iterator.
239
289
  *
240
290
  * @returns
@@ -269,6 +319,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
269
319
  * This means that the original iterator won't be consumed until the
270
320
  * new one is and that consuming one of them will consume the other as well.
271
321
  *
322
+ * ---
323
+ *
324
+ * @example
272
325
  * ```ts
273
326
  * const results = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
274
327
  * .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
@@ -277,6 +330,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
277
330
  * console.log(await results.toObject()); // { odd: [3, 5], even: [0, 2, 6, 8] }
278
331
  * ```
279
332
  *
333
+ * ---
334
+ *
280
335
  * @param predicate The condition to check for each element of the iterator.
281
336
  *
282
337
  * @returns A new {@link AggregatedAsyncIterator} containing the elements that satisfy the condition.
@@ -293,6 +348,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
293
348
  * This means that the original iterator won't be consumed until the
294
349
  * new one is and that consuming one of them will consume the other as well.
295
350
  *
351
+ * ---
352
+ *
353
+ * @example
296
354
  * ```ts
297
355
  * const results = new SmartAsyncIterator<number>([-3, "-1", 0, "2", "3", 5, 6, "8"])
298
356
  * .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
@@ -301,6 +359,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
301
359
  * console.log(await results.toObject()); // { odd: [-3, 5], even: [0, 6] }
302
360
  * ```
303
361
  *
362
+ * ---
363
+ *
304
364
  * @template S
305
365
  * The type of the elements that satisfy the condition.
306
366
  * This allows the type-system to infer the correct type of the new iterator.
@@ -342,6 +402,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
342
402
  * This means that the original iterator won't be consumed until the
343
403
  * new one is and that consuming one of them will consume the other as well.
344
404
  *
405
+ * ---
406
+ *
407
+ * @example
345
408
  * ```ts
346
409
  * const results = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
347
410
  * .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
@@ -350,6 +413,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
350
413
  * console.log(await results.toObject()); // { odd: [3, 1, 3, 5], even: [0, 2, 6, 8] }
351
414
  * ```
352
415
  *
416
+ * ---
417
+ *
353
418
  * @template V The type of the elements after the transformation.
354
419
  *
355
420
  * @param iteratee The transformation function to apply to each element of the iterator.
@@ -387,6 +452,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
387
452
  * object that will contain all the reduced results for each group.
388
453
  * If the iterator is infinite, the method will never return.
389
454
  *
455
+ * ---
456
+ *
457
+ * @example
390
458
  * ```ts
391
459
  * const results = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
392
460
  * .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
@@ -395,6 +463,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
395
463
  * console.log(await results.toObject()); // { odd: 4, even: 16 }
396
464
  * ```
397
465
  *
466
+ * ---
467
+ *
398
468
  * @param reducer The reducer function to apply to each element of the iterator.
399
469
  *
400
470
  * @returns
@@ -416,6 +486,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
416
486
  * object that will contain all the reduced results for each group.
417
487
  * If the iterator is infinite, the method will never return.
418
488
  *
489
+ * ---
490
+ *
491
+ * @example
419
492
  * ```ts
420
493
  * const results = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
421
494
  * .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
@@ -424,6 +497,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
424
497
  * console.log(await results.toObject()); // { odd: 4, even: 16 }
425
498
  * ```
426
499
  *
500
+ * ---
501
+ *
427
502
  * @template A The type of the accumulator value which will also be the final result of the reduction.
428
503
  *
429
504
  * @param reducer The reducer function to apply to each element of the iterator.
@@ -449,6 +524,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
449
524
  * object that will contain all the reduced results for each group.
450
525
  * If the iterator is infinite, the method will never return.
451
526
  *
527
+ * ---
528
+ *
529
+ * @example
452
530
  * ```ts
453
531
  * const results = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
454
532
  * .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
@@ -457,6 +535,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
457
535
  * console.log(await results.toObject()); // { odd: { value: 4 }, even: { value: 16 } }
458
536
  * ```
459
537
  *
538
+ * ---
539
+ *
460
540
  * @template A The type of the accumulator value which will also be the final result of the reduction.
461
541
  *
462
542
  * @param reducer The reducer function to apply to each element of the iterator.
@@ -515,6 +595,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
515
595
  * This means that the original iterator won't be consumed until the
516
596
  * new one is and that consuming one of them will consume the other as well.
517
597
  *
598
+ * ---
599
+ *
600
+ * @example
518
601
  * ```ts
519
602
  * const results = new SmartAsyncIterator<number>([[-3, -1], 0, 2, 3, 5, [6, 8]])
520
603
  * .groupBy(async (values) =>
@@ -527,6 +610,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
527
610
  * console.log(await results.toObject()); // { odd: [-3, -1, 3, 5], even: [0, 2, 6, 8] }
528
611
  * ```
529
612
  *
613
+ * ---
614
+ *
530
615
  * @template V The type of the elements after the transformation.
531
616
  *
532
617
  * @param iteratee The transformation function to apply to each element of the iterator.
@@ -568,6 +653,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
568
653
  * This means that the original iterator won't be consumed until the
569
654
  * new one is and that consuming one of them will consume the other as well.
570
655
  *
656
+ * ---
657
+ *
658
+ * @example
571
659
  * ```ts
572
660
  * const results = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
573
661
  * .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
@@ -576,6 +664,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
576
664
  * console.log(await results.toObject()); // { odd: [3, 5], even: [6, 8] }
577
665
  * ```
578
666
  *
667
+ * ---
668
+ *
579
669
  * @param count The number of elements to drop from the beginning of each group.
580
670
  *
581
671
  * @returns A new {@link AggregatedAsyncIterator} containing the remaining elements.
@@ -614,6 +704,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
614
704
  * This means that the original iterator won't be consumed until the
615
705
  * new one is and that consuming one of them will consume the other as well.
616
706
  *
707
+ * ---
708
+ *
709
+ * @example
617
710
  * ```ts
618
711
  * const results = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
619
712
  * .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
@@ -622,7 +715,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
622
715
  * console.log(await results.toObject()); // { odd: [-3, -1], even: [0, 2] }
623
716
  * ```
624
717
  *
625
- * @param count The number of elements to take from the beginning of each group.
718
+ * ---
719
+ *
720
+ * @param limit The number of elements to take from the beginning of each group.
626
721
  *
627
722
  * @returns A new {@link AggregatedAsyncIterator} containing the taken elements.
628
723
  */
@@ -657,6 +752,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
657
752
  * object that will contain the first element that satisfies the condition for each group.
658
753
  * If the iterator is infinite, the method will never return.
659
754
  *
755
+ * ---
756
+ *
757
+ * @example
660
758
  * ```ts
661
759
  * const results = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
662
760
  * .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
@@ -665,6 +763,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
665
763
  * console.log(await results.toObject()); // { odd: 3, even: 2 }
666
764
  * ```
667
765
  *
766
+ * ---
767
+ *
668
768
  * @param predicate The condition to check for each element of the iterator.
669
769
  *
670
770
  * @returns
@@ -685,6 +785,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
685
785
  * object that will contain the first element that satisfies the condition for each group.
686
786
  * If the iterator is infinite, the method will never return.
687
787
  *
788
+ * ---
789
+ *
790
+ * @example
688
791
  * ```ts
689
792
  * const results = new SmartAsyncIterator<number | string>([-3, "-1", 0, "2", "3", 5, 6, "8"])
690
793
  * .groupBy(async (value) => Number(value) % 2 === 0 ? "even" : "odd")
@@ -693,6 +796,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
693
796
  * console.log(await results.toObject()); // { odd: -3, even: 0 }
694
797
  * ```
695
798
  *
799
+ * ---
800
+ *
696
801
  * @template S
697
802
  * The type of the elements that satisfy the condition.
698
803
  * This allows the type-system to infer the correct type of the new iterator.
@@ -739,6 +844,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
739
844
  * This means that the original iterator won't be consumed until the
740
845
  * new one is and that consuming one of them will consume the other as well.
741
846
  *
847
+ * ---
848
+ *
849
+ * @example
742
850
  * ```ts
743
851
  * const results = new SmartAsyncIterator<number>([-3, 0, 2, -1, 3])
744
852
  * .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
@@ -747,6 +855,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
747
855
  * console.log(results.toObject()); // { odd: [[0, -3], [1, -1], [2, 3]], even: [[0, 0], [1, 2]] }
748
856
  * ```
749
857
  *
858
+ * ---
859
+ *
750
860
  * @returns A new {@link AggregatedAsyncIterator} containing the enumerated elements.
751
861
  */
752
862
  public enumerate(): AggregatedAsyncIterator<K, [number, T]>
@@ -765,6 +875,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
765
875
  * This means that the original iterator won't be consumed until the
766
876
  * new one is and that consuming one of them will consume the other as well.
767
877
  *
878
+ * ---
879
+ *
880
+ * @example
768
881
  * ```ts
769
882
  * const results = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 6, -3, -1, 0, 5, 6, 8, 0, 2])
770
883
  * .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
@@ -773,6 +886,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
773
886
  * console.log(await results.toObject()); // { odd: [-3, -1, 3, 5], even: [0, 2, 6, 8] }
774
887
  * ```
775
888
  *
889
+ * ---
890
+ *
776
891
  * @returns A new {@link AggregatedAsyncIterator} containing only the unique elements.
777
892
  */
778
893
  public unique(): AggregatedAsyncIterator<K, T>
@@ -801,6 +916,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
801
916
  *
802
917
  * If the iterator is infinite, the method will never return.
803
918
  *
919
+ * ---
920
+ *
921
+ * @example
804
922
  * ```ts
805
923
  * const results = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
806
924
  * .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
@@ -809,6 +927,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
809
927
  * console.log(await results.toObject()); // { odd: 4, even: 4 }
810
928
  * ```
811
929
  *
930
+ * ---
931
+ *
812
932
  * @returns
813
933
  * A {@link Promise} resolving to a new {@link ReducedIterator} containing the number of elements for each group.
814
934
  */
@@ -836,6 +956,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
836
956
  * This method will consume the entire iterator in the process.
837
957
  * If the iterator is infinite, the method will never return.
838
958
  *
959
+ * ---
960
+ *
961
+ * @example
839
962
  * ```ts
840
963
  * const aggregator = new SmartAsyncIterator<number>([-3, 0, 2, -1, 3])
841
964
  * .groupBy(async (value) => value % 2 === 0 ? "even" : "odd");
@@ -846,6 +969,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
846
969
  * };
847
970
  * ```
848
971
  *
972
+ * ---
973
+ *
849
974
  * @param iteratee The function to execute for each element of the iterator.
850
975
  *
851
976
  * @returns A {@link Promise} that will resolve once the iteration is complete.
@@ -875,6 +1000,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
875
1000
  * This means that the original iterator won't be consumed until the
876
1001
  * new one is and that consuming one of them will consume the other as well.
877
1002
  *
1003
+ * ---
1004
+ *
1005
+ * @example
878
1006
  * ```ts
879
1007
  * const results = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
880
1008
  * .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
@@ -884,6 +1012,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
884
1012
  * console.log(await results.toObject()); // { "+": [1, 0, 3, 6], "-": [-3, -2, -5, -8] }
885
1013
  * ```
886
1014
  *
1015
+ * ---
1016
+ *
887
1017
  * @template J The type of the new key.
888
1018
  *
889
1019
  * @param iteratee The function to determine the new key for each element of the iterator.
@@ -919,6 +1049,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
919
1049
  * This means that the original iterator won't be consumed until the
920
1050
  * new one is and that consuming one of them will consume the other as well.
921
1051
  *
1052
+ * ---
1053
+ *
1054
+ * @example
922
1055
  * ```ts
923
1056
  * const keys = new SmartAsyncIterator([-3, Symbol(), "A", { }, null, [1 , 2, 3], false])
924
1057
  * .groupBy(async (value) => typeof value)
@@ -927,6 +1060,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
927
1060
  * console.log(await keys.toArray()); // ["number", "symbol", "string", "object", "boolean"]
928
1061
  * ```
929
1062
  *
1063
+ * ---
1064
+ *
930
1065
  * @returns A new {@link SmartAsyncIterator} containing all the keys of the iterator.
931
1066
  */
932
1067
  public keys(): SmartAsyncIterator<K>
@@ -958,6 +1093,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
958
1093
  * This means that the original iterator won't be consumed until the
959
1094
  * new one is and that consuming one of them will consume the other as well.
960
1095
  *
1096
+ * ---
1097
+ *
1098
+ * @example
961
1099
  * ```ts
962
1100
  * const entries = new SmartAsyncIterator<number>([-3, 0, 2, -1, 3])
963
1101
  * .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
@@ -966,6 +1104,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
966
1104
  * console.log(await entries.toArray()); // [["odd", -3], ["even", 0], ["even", 2], ["odd", -1], ["odd", 3]]
967
1105
  * ```
968
1106
  *
1107
+ * ---
1108
+ *
969
1109
  * @returns A new {@link SmartAsyncIterator} containing all the entries of the iterator.
970
1110
  */
971
1111
  public entries(): SmartAsyncIterator<[K, T]>
@@ -984,6 +1124,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
984
1124
  * This means that the original iterator won't be consumed until the
985
1125
  * new one is and that consuming one of them will consume the other as well.
986
1126
  *
1127
+ * ---
1128
+ *
1129
+ * @example
987
1130
  * ```ts
988
1131
  * const values = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
989
1132
  * .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
@@ -992,6 +1135,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
992
1135
  * console.log(await values.toArray()); // [-3, -1, 0, 2, 3, 5, 6, 8]
993
1136
  * ```
994
1137
  *
1138
+ * ---
1139
+ *
995
1140
  * @returns A new {@link SmartAsyncIterator} containing all the values of the iterator.
996
1141
  */
997
1142
  public values(): SmartAsyncIterator<T>
@@ -1010,6 +1155,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
1010
1155
  *
1011
1156
  * If the iterator is infinite, the method will never return.
1012
1157
  *
1158
+ * ---
1159
+ *
1160
+ * @example
1013
1161
  * ```ts
1014
1162
  * const aggregator = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
1015
1163
  * .groupBy(async (value) => value % 2 === 0 ? "even" : "odd");
@@ -1017,6 +1165,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
1017
1165
  * console.log(await aggregator.toArray()); // [[-3, -1, 3, 5], [0, 2, 6, 8]]
1018
1166
  * ```
1019
1167
  *
1168
+ * ---
1169
+ *
1020
1170
  * @returns A {@link Promise} resolving to an {@link Array} containing all the values of the iterator.
1021
1171
  */
1022
1172
  public async toArray(): Promise<T[][]>
@@ -1032,6 +1182,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
1032
1182
  *
1033
1183
  * If the iterator is infinite, the method will never return.
1034
1184
  *
1185
+ * ---
1186
+ *
1187
+ * @example
1035
1188
  * ```ts
1036
1189
  * const aggregator = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
1037
1190
  * .groupBy(async (value) => value % 2 === 0 ? "even" : "odd");
@@ -1039,6 +1192,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
1039
1192
  * console.log(await aggregator.toMap()); // Map(2) { "odd" => [-3, -1, 3, 5], "even" => [0, 2, 6, 8] }
1040
1193
  * ```
1041
1194
  *
1195
+ * ---
1196
+ *
1042
1197
  * @returns A {@link Promise} resolving to a {@link Map} containing all the entries of the iterator.
1043
1198
  */
1044
1199
  public async toMap(): Promise<Map<K, T[]>>
@@ -1062,6 +1217,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
1062
1217
  *
1063
1218
  * If the iterator is infinite, the method will never return.
1064
1219
  *
1220
+ * ---
1221
+ *
1222
+ * @example
1065
1223
  * ```ts
1066
1224
  * const aggregator = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
1067
1225
  * .groupBy(async (value) => value % 2 === 0 ? "even" : "odd");
@@ -1069,6 +1227,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
1069
1227
  * console.log(await aggregator.toObject()); // { odd: [-3, -1, 3, 5], even: [0, 2, 6, 8] }
1070
1228
  * ```
1071
1229
  *
1230
+ * ---
1231
+ *
1072
1232
  * @returns A {@link Promise} resolving to an object containing all the entries of the iterator.
1073
1233
  */
1074
1234
  public async toObject(): Promise<Record<K, T[]>>