@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.
@@ -51,10 +51,15 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
51
51
  /**
52
52
  * Initializes a new instance of the {@link SmartAsyncIterator} class.
53
53
  *
54
+ * ---
55
+ *
56
+ * @example
54
57
  * ```ts
55
58
  * const iterator = new SmartAsyncIterator<string>(["A", "B", "C"]);
56
59
  * ```
57
60
  *
61
+ * ---
62
+ *
58
63
  * @param iterable The iterable object to wrap.
59
64
  */
60
65
  public constructor(iterable: Iterable<T>);
@@ -62,10 +67,15 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
62
67
  /**
63
68
  * Initializes a new instance of the {@link SmartAsyncIterator} class.
64
69
  *
70
+ * ---
71
+ *
72
+ * @example
65
73
  * ```ts
66
74
  * const iterator = new SmartAsyncIterator<number>([1, 2, 3, 4, 5]);
67
75
  * ```
68
76
  *
77
+ * ---
78
+ *
69
79
  * @param iterable The asynchronous iterable object to wrap.
70
80
  */
71
81
  public constructor(iterable: AsyncIterable<T>);
@@ -73,6 +83,9 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
73
83
  /**
74
84
  * Initializes a new instance of the {@link SmartAsyncIterator} class.
75
85
  *
86
+ * ---
87
+ *
88
+ * @example
76
89
  * ```ts
77
90
  * const iterator = new SmartAsyncIterator<number, void, number>({
78
91
  * _sum: 0, _count: 0,
@@ -87,6 +100,8 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
87
100
  * })
88
101
  * ```
89
102
  *
103
+ * ---
104
+ *
90
105
  * @param iterator The iterator object to wrap.
91
106
  */
92
107
  public constructor(iterator: Iterator<T, R, N>);
@@ -94,6 +109,9 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
94
109
  /**
95
110
  * Initializes a new instance of the {@link SmartAsyncIterator} class.
96
111
  *
112
+ * ---
113
+ *
114
+ * @example
97
115
  * ```ts
98
116
  * const iterator = new SmartAsyncIterator<number, void, number>({
99
117
  * _sum: 0, _count: 0,
@@ -108,6 +126,8 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
108
126
  * })
109
127
  * ```
110
128
  *
129
+ * ---
130
+ *
111
131
  * @param iterator The asynchronous iterator object to wrap.
112
132
  */
113
133
  public constructor(iterator: AsyncIterator<T, R, N>);
@@ -115,6 +135,9 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
115
135
  /**
116
136
  * Initializes a new instance of the {@link SmartAsyncIterator} class.
117
137
  *
138
+ * ---
139
+ *
140
+ * @example
118
141
  * ```ts
119
142
  * const iterator = new SmartAsyncIterator<number>(function* ()
120
143
  * {
@@ -122,6 +145,8 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
122
145
  * });
123
146
  * ```
124
147
  *
148
+ * ---
149
+ *
125
150
  * @param generatorFn The generator function to wrap.
126
151
  */
127
152
  public constructor(generatorFn: GeneratorFunction<T, R, N>);
@@ -129,6 +154,9 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
129
154
  /**
130
155
  * Initializes a new instance of the {@link SmartAsyncIterator} class.
131
156
  *
157
+ * ---
158
+ *
159
+ * @example
132
160
  * ```ts
133
161
  * const iterator = new SmartAsyncIterator<number>(async function* ()
134
162
  * {
@@ -136,6 +164,8 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
136
164
  * });
137
165
  * ```
138
166
  *
167
+ * ---
168
+ *
139
169
  * @param generatorFn The asynchronous generator function to wrap.
140
170
  */
141
171
  public constructor(generatorFn: AsyncGeneratorFunction<T, R, N>);
@@ -143,10 +173,15 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
143
173
  /**
144
174
  * Initializes a new instance of the {@link SmartAsyncIterator} class.
145
175
  *
176
+ * ---
177
+ *
178
+ * @example
146
179
  * ```ts
147
180
  * const iterator = new SmartAsyncIterator(values);
148
181
  * ```
149
182
  *
183
+ * ---
184
+ *
150
185
  * @param argument The synchronous or asynchronous iterable, iterator or generator function to wrap.
151
186
  */
152
187
  public constructor(argument: MaybeAsyncIteratorLike<T, R, N> | MaybeAsyncGeneratorFunction<T, R, N>);
@@ -226,6 +261,9 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
226
261
  *
227
262
  * If the iterator is infinite and every element satisfies the condition, the method will never return.
228
263
  *
264
+ * ---
265
+ *
266
+ * @example
229
267
  * ```ts
230
268
  * const iterator = new SmartAsyncIterator<number>([-2, -1, 0, 1, 2]);
231
269
  * const result = await iterator.every(async (value) => value < 0);
@@ -233,6 +271,8 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
233
271
  * console.log(result); // false
234
272
  * ```
235
273
  *
274
+ * ---
275
+ *
236
276
  * @param predicate The condition to check for each element of the iterator.
237
277
  *
238
278
  * @returns
@@ -266,6 +306,9 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
266
306
  *
267
307
  * If the iterator is infinite and no element satisfies the condition, the method will never return.
268
308
  *
309
+ * ---
310
+ *
311
+ * @example
269
312
  * ```ts
270
313
  * const iterator = new SmartAsyncIterator<number>([-2, -1, 0, 1, 2]);
271
314
  * const result = await iterator.some(async (value) => value > 0);
@@ -273,6 +316,8 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
273
316
  * console.log(result); // true
274
317
  * ```
275
318
  *
319
+ * ---
320
+ *
276
321
  * @param predicate The condition to check for each element of the iterator.
277
322
  *
278
323
  * @returns
@@ -306,6 +351,9 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
306
351
  * This means that the original iterator won't be consumed until the
307
352
  * new one is and that consuming one of them will consume the other as well.
308
353
  *
354
+ * ---
355
+ *
356
+ * @example
309
357
  * ```ts
310
358
  * const iterator = new SmartAsyncIterator<number>([-2, -1, 0, 1, 2]);
311
359
  * const result = iterator.filter(async (value) => value < 0);
@@ -313,6 +361,8 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
313
361
  * console.log(await result.toArray()); // [-2, -1]
314
362
  * ```
315
363
  *
364
+ * ---
365
+ *
316
366
  * @param predicate The condition to check for each element of the iterator.
317
367
  *
318
368
  * @returns A new {@link SmartAsyncIterator} containing only the elements that satisfy the condition.
@@ -332,6 +382,9 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
332
382
  * This means that the original iterator won't be consumed until the
333
383
  * new one is and that consuming one of them will consume the other as well.
334
384
  *
385
+ * ---
386
+ *
387
+ * @example
335
388
  * ```ts
336
389
  * const iterator = new SmartAsyncIterator<number | string>([-2, "-1", "0", 1, "2"]);
337
390
  * const result = iterator.filter<number>(async (value) => typeof value === "number");
@@ -339,6 +392,8 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
339
392
  * console.log(await result.toArray()); // [-2, 1]
340
393
  * ```
341
394
  *
395
+ * ---
396
+ *
342
397
  * @template S
343
398
  * The type of the elements that satisfy the condition.
344
399
  * This allows the type-system to infer the correct type of the new iterator.
@@ -381,6 +436,9 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
381
436
  * This means that the original iterator won't be consumed until the
382
437
  * new one is and that consuming one of them will consume the other as well.
383
438
  *
439
+ * ---
440
+ *
441
+ * @example
384
442
  * ```ts
385
443
  * const iterator = new SmartAsyncIterator<number>([-2, -1, 0, 1, 2]);
386
444
  * const result = iterator.map(async (value) => Math.abs(value));
@@ -388,6 +446,8 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
388
446
  * console.log(await result.toArray()); // [2, 1, 0, 1, 2]
389
447
  * ```
390
448
  *
449
+ * ---
450
+ *
391
451
  * @template V The type of the elements after the transformation.
392
452
  *
393
453
  * @param iteratee The transformation function to apply to each element of the iterator.
@@ -427,6 +487,9 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
427
487
  * - If an empty iterator is provided, a {@link ValueException} will be thrown.
428
488
  * - If the iterator is infinite, the method will never return.
429
489
  *
490
+ * ---
491
+ *
492
+ * @example
430
493
  * ```ts
431
494
  * const iterator = new SmartAsyncIterator<number>([1, 2, 3, 4, 5]);
432
495
  * const result = await iterator.reduce(async (acc, value) => acc + value);
@@ -434,6 +497,8 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
434
497
  * console.log(result); // 15
435
498
  * ```
436
499
  *
500
+ * ---
501
+ *
437
502
  * @param reducer The reducer function to apply to each element of the iterator.
438
503
  *
439
504
  * @returns A {@link Promise} that will resolve to the final result of the reduction.
@@ -452,6 +517,9 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
452
517
  *
453
518
  * If the iterator is infinite, the method will never return.
454
519
  *
520
+ * ---
521
+ *
522
+ * @example
455
523
  * ```ts
456
524
  * const iterator = new SmartAsyncIterator<number>([1, 2, 3, 4, 5]);
457
525
  * const result = await iterator.reduce(async (acc, value) => acc + value, 10);
@@ -459,6 +527,8 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
459
527
  * console.log(result); // 25
460
528
  * ```
461
529
  *
530
+ * ---
531
+ *
462
532
  * @template A The type of the accumulator value which will also be the type of the final result of the reduction.
463
533
  *
464
534
  * @param reducer The reducer function to apply to each element of the iterator.
@@ -504,6 +574,9 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
504
574
  * This means that the original iterator won't be consumed until the
505
575
  * new one is and that consuming one of them will consume the other as well.
506
576
  *
577
+ * ---
578
+ *
579
+ * @example
507
580
  * ```ts
508
581
  * const iterator = new SmartAsyncIterator<number[]>([[-2, -1], 0, 1, 2, [3, 4, 5]]);
509
582
  * const result = iterator.flatMap(async (value) => value);
@@ -511,6 +584,8 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
511
584
  * console.log(await result.toArray()); // [-2, -1, 0, 1, 2, 3, 4, 5]
512
585
  * ```
513
586
  *
587
+ * ---
588
+ *
514
589
  * @template V The type of the elements after the transformation.
515
590
  *
516
591
  * @param iteratee The transformation function to apply to each element of the iterator.
@@ -556,6 +631,9 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
556
631
  * Only the dropped elements will be consumed in the process.
557
632
  * The rest of the iterator will be consumed only once the new one is.
558
633
  *
634
+ * ---
635
+ *
636
+ * @example
559
637
  * ```ts
560
638
  * const iterator = new SmartAsyncIterator<number>([-2, -1, 0, 1, 2]);
561
639
  * const result = iterator.drop(3);
@@ -563,6 +641,8 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
563
641
  * console.log(await result.toArray()); // [1, 2]
564
642
  * ```
565
643
  *
644
+ * ---
645
+ *
566
646
  * @param count The number of elements to drop.
567
647
  *
568
648
  * @returns A new {@link SmartAsyncIterator} containing the remaining elements.
@@ -607,6 +687,9 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
607
687
  * Only the taken elements will be consumed from the original iterator.
608
688
  * The rest of the original iterator will be available for further consumption.
609
689
  *
690
+ * ---
691
+ *
692
+ * @example
610
693
  * ```ts
611
694
  * const iterator = new SmartAsyncIterator<number>([-2, -1, 0, 1, 2]);
612
695
  * const result = iterator.take(3);
@@ -615,6 +698,8 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
615
698
  * console.log(await iterator.toArray()); // [1, 2]
616
699
  * ```
617
700
  *
701
+ * ---
702
+ *
618
703
  * @param limit The number of elements to take.
619
704
  *
620
705
  * @returns A new {@link SmartAsyncIterator} containing the taken elements.
@@ -654,6 +739,9 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
654
739
  * - If no element satisfies the condition, `undefined` will be returned once the entire iterator is consumed.
655
740
  * - If the iterator is infinite and no element satisfies the condition, the method will never return.
656
741
  *
742
+ * ---
743
+ *
744
+ * @example
657
745
  * ```ts
658
746
  * const iterator = new SmartAsyncIterator<number>([-2, -1, 0, 1, 2]);
659
747
  * const result = await iterator.find(async (value) => value > 0);
@@ -661,6 +749,8 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
661
749
  * console.log(result); // 1
662
750
  * ```
663
751
  *
752
+ * ---
753
+ *
664
754
  * @param predicate The condition to check for each element of the iterator.
665
755
  *
666
756
  * @returns
@@ -682,6 +772,9 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
682
772
  * - If no element satisfies the condition, `undefined` will be returned once the entire iterator is consumed.
683
773
  * - If the iterator is infinite and no element satisfies the condition, the method will never return.
684
774
  *
775
+ * ---
776
+ *
777
+ * @example
685
778
  * ```ts
686
779
  * const iterator = new SmartAsyncIterator<number | string>([-2, "-1", "0", 1, "2"]);
687
780
  * const result = await iterator.find<number>(async (value) => typeof value === "number");
@@ -689,6 +782,8 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
689
782
  * console.log(result); // -2
690
783
  * ```
691
784
  *
785
+ * ---
786
+ *
692
787
  * @template S
693
788
  * The type of the element that satisfies the condition.
694
789
  * This allows the type-system to infer the correct type of the result.
@@ -727,6 +822,9 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
727
822
  * This means that the original iterator won't be consumed until the
728
823
  * new one is and that consuming one of them will consume the other as well.
729
824
  *
825
+ * ---
826
+ *
827
+ * @example
730
828
  * ```ts
731
829
  * const iterator = new SmartAsyncIterator<string>(["A", "M", "N", "Z"]);
732
830
  * const result = iterator.enumerate();
@@ -737,6 +835,8 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
737
835
  * }
738
836
  * ```
739
837
  *
838
+ * ---
839
+ *
740
840
  * @returns A new {@link SmartAsyncIterator} containing the enumerated elements.
741
841
  */
742
842
  public enumerate(): SmartAsyncIterator<[number, T], R>
@@ -755,6 +855,9 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
755
855
  * This means that the original iterator won't be consumed until the
756
856
  * new one is and that consuming one of them will consume the other as well.
757
857
  *
858
+ * ---
859
+ *
860
+ * @example
758
861
  * ```ts
759
862
  * const iterator = new SmartAsyncIterator<number>([1, 1, 2, 3, 2, 3, 4, 5, 5, 4]);
760
863
  * const result = iterator.unique();
@@ -762,6 +865,8 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
762
865
  * console.log(await result.toArray()); // [1, 2, 3, 4, 5]
763
866
  * ```
764
867
  *
868
+ * ---
869
+ *
765
870
  * @returns A new {@link SmartAsyncIterator} containing only the unique elements.
766
871
  */
767
872
  public unique(): SmartAsyncIterator<T, R>
@@ -790,6 +895,9 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
790
895
  *
791
896
  * If the iterator is infinite, the method will never return.
792
897
  *
898
+ * ---
899
+ *
900
+ * @example
793
901
  * ```ts
794
902
  * const iterator = new SmartAsyncIterator<number>([1, 2, 3, 4, 5]);
795
903
  * const result = await iterator.count();
@@ -797,6 +905,8 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
797
905
  * console.log(result); // 5
798
906
  * ```
799
907
  *
908
+ * ---
909
+ *
800
910
  * @returns A {@link Promise} that will resolve to the number of elements in the iterator.
801
911
  */
802
912
  public async count(): Promise<number>
@@ -819,6 +929,9 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
819
929
  * This method will consume the entire iterator in the process.
820
930
  * If the iterator is infinite, the method will never return.
821
931
  *
932
+ * ---
933
+ *
934
+ * @example
822
935
  * ```ts
823
936
  * const iterator = new SmartAsyncIterator<number>(["A", "M", "N", "Z"]);
824
937
  * await iterator.forEach(async (value, index) =>
@@ -827,6 +940,8 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
827
940
  * }
828
941
  * ```
829
942
  *
943
+ * ---
944
+ *
830
945
  * @param iteratee The function to apply to each element of the iterator.
831
946
  *
832
947
  * @returns A {@link Promise} that will resolve once the iteration is complete.
@@ -852,6 +967,9 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
852
967
  *
853
968
  * Once the iterator is done, the method will return an object with the `done` property set to `true`.
854
969
  *
970
+ * ---
971
+ *
972
+ * @example
855
973
  * ```ts
856
974
  * const iterator = new SmartAsyncIterator<number>([1, 2, 3, 4, 5]);
857
975
  *
@@ -866,6 +984,8 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
866
984
  * console.log(result); // { done: true, value: undefined }
867
985
  * ```
868
986
  *
987
+ * ---
988
+ *
869
989
  * @param values The value to pass to the next element, if required.
870
990
  *
871
991
  * @returns
@@ -881,6 +1001,9 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
881
1001
  * free the resources and perform any cleanup operation.
882
1002
  * It may also be used to signal the end or to compute a specific final result of the iteration process.
883
1003
  *
1004
+ * ---
1005
+ *
1006
+ * @example
884
1007
  * ```ts
885
1008
  * const iterator = new SmartAsyncIterator<number>({
886
1009
  * _index: 0,
@@ -899,6 +1022,8 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
899
1022
  * }
900
1023
  * ```
901
1024
  *
1025
+ * ---
1026
+ *
902
1027
  * @param value The final value of the iterator.
903
1028
  *
904
1029
  * @returns A {@link Promise} that will resolve to the final result of the iterator.
@@ -917,6 +1042,9 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
917
1042
  * free the resources and perform any cleanup operation.
918
1043
  * It may also be used to signal that an error occurred during the iteration process or to handle it.
919
1044
  *
1045
+ * ---
1046
+ *
1047
+ * @example
920
1048
  * ```ts
921
1049
  * const iterator = new SmartAsyncIterator<number>({
922
1050
  * _index: 0,
@@ -944,6 +1072,8 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
944
1072
  * }
945
1073
  * ```
946
1074
  *
1075
+ * ---
1076
+ *
947
1077
  * @param error The error to throw into the iterator.
948
1078
  *
949
1079
  * @returns A {@link Promise} that will resolve to the final result of the iterator.
@@ -967,6 +1097,9 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
967
1097
  * This means that the original iterator won't be consumed until the
968
1098
  * the new one is and that consuming one of them will consume the other as well.
969
1099
  *
1100
+ * ---
1101
+ *
1102
+ * @example
970
1103
  * ```ts
971
1104
  * const iterator = new SmartAsyncIterator<number>([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
972
1105
  * const result = iterator.groupBy<string>(async (value) => value % 2 === 0 ? "even" : "odd");
@@ -974,6 +1107,8 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
974
1107
  * console.log(await result.toObject()); // { odd: [1, 3, 5, 7, 9], even: [2, 4, 6, 8, 10] }
975
1108
  * ```
976
1109
  *
1110
+ * ---
1111
+ *
977
1112
  * @template K The type of the keys used to group the elements.
978
1113
  *
979
1114
  * @param iteratee The key function to apply to each element of the iterator.
@@ -996,6 +1131,9 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
996
1131
  *
997
1132
  * If the iterator is infinite, the method will never return.
998
1133
  *
1134
+ * ---
1135
+ *
1136
+ * @example
999
1137
  * ```ts
1000
1138
  * const iterator = new SmartAsyncIterator(async function* ()
1001
1139
  * {
@@ -1006,6 +1144,8 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
1006
1144
  * console.log(result); // [0, 1, 2, 3, 4]
1007
1145
  * ```
1008
1146
  *
1147
+ * ---
1148
+ *
1009
1149
  * @returns A {@link Promise} that will resolve to an array containing all elements of the iterator.
1010
1150
  */
1011
1151
  public toArray(): Promise<T[]>