@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
|
@@ -42,10 +42,15 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
42
42
|
/**
|
|
43
43
|
* Initializes a new instance of the {@link SmartIterator} class.
|
|
44
44
|
*
|
|
45
|
+
* ---
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
45
48
|
* ```ts
|
|
46
49
|
* const iterator = new SmartIterator<string>(["A", "B", "C"]);
|
|
47
50
|
* ```
|
|
48
51
|
*
|
|
52
|
+
* ---
|
|
53
|
+
*
|
|
49
54
|
* @param iterable The iterable object to wrap.
|
|
50
55
|
*/
|
|
51
56
|
public constructor(iterable: Iterable<T, R, N>);
|
|
@@ -53,6 +58,9 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
53
58
|
/**
|
|
54
59
|
* Initializes a new instance of the {@link SmartIterator} class.
|
|
55
60
|
*
|
|
61
|
+
* ---
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
56
64
|
* ```ts
|
|
57
65
|
* const iterator = new SmartIterator<number, void, number>({
|
|
58
66
|
* _sum: 0, _count: 0,
|
|
@@ -67,6 +75,8 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
67
75
|
* })
|
|
68
76
|
* ```
|
|
69
77
|
*
|
|
78
|
+
* ---
|
|
79
|
+
*
|
|
70
80
|
* @param iterator The iterator object to wrap.
|
|
71
81
|
*/
|
|
72
82
|
public constructor(iterator: Iterator<T, R, N>);
|
|
@@ -74,6 +84,9 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
74
84
|
/**
|
|
75
85
|
* Initializes a new instance of the {@link SmartIterator} class.
|
|
76
86
|
*
|
|
87
|
+
* ---
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
77
90
|
* ```ts
|
|
78
91
|
* const iterator = new SmartIterator<number>(function* ()
|
|
79
92
|
* {
|
|
@@ -81,6 +94,8 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
81
94
|
* });
|
|
82
95
|
* ```
|
|
83
96
|
*
|
|
97
|
+
* ---
|
|
98
|
+
*
|
|
84
99
|
* @param generatorFn The generator function to wrap.
|
|
85
100
|
*/
|
|
86
101
|
public constructor(generatorFn: GeneratorFunction<T, R, N>);
|
|
@@ -88,10 +103,15 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
88
103
|
/**
|
|
89
104
|
* Initializes a new instance of the {@link SmartIterator} class.
|
|
90
105
|
*
|
|
106
|
+
* ---
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
91
109
|
* ```ts
|
|
92
110
|
* const iterator = new SmartIterator(values);
|
|
93
111
|
* ```
|
|
94
112
|
*
|
|
113
|
+
* ---
|
|
114
|
+
*
|
|
95
115
|
* @param argument The iterable, iterator or generator function to wrap.
|
|
96
116
|
*/
|
|
97
117
|
public constructor(argument: IteratorLike<T, R, N> | GeneratorFunction<T, R, N>);
|
|
@@ -124,6 +144,9 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
124
144
|
*
|
|
125
145
|
* If the iterator is infinite and every element satisfies the condition, the method will never return.
|
|
126
146
|
*
|
|
147
|
+
* ---
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
127
150
|
* ```ts
|
|
128
151
|
* const iterator = new SmartIterator<number>([-2, -1, 0, 1, 2]);
|
|
129
152
|
* const result = iterator.every((value) => value < 0);
|
|
@@ -131,6 +154,8 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
131
154
|
* console.log(result); // false
|
|
132
155
|
* ```
|
|
133
156
|
*
|
|
157
|
+
* ---
|
|
158
|
+
*
|
|
134
159
|
* @param predicate The condition to check for each element of the iterator.
|
|
135
160
|
*
|
|
136
161
|
* @returns `true` if all elements satisfy the condition, `false` otherwise.
|
|
@@ -163,6 +188,9 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
163
188
|
*
|
|
164
189
|
* If the iterator is infinite and no element satisfies the condition, the method will never return.
|
|
165
190
|
*
|
|
191
|
+
* ---
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
166
194
|
* ```ts
|
|
167
195
|
* const iterator = new SmartIterator<number>([-2, -1, 0, 1, 2]);
|
|
168
196
|
* const result = iterator.some((value) => value < 0);
|
|
@@ -170,6 +198,8 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
170
198
|
* console.log(result); // true
|
|
171
199
|
* ```
|
|
172
200
|
*
|
|
201
|
+
* ---
|
|
202
|
+
*
|
|
173
203
|
* @param predicate The condition to check for each element of the iterator.
|
|
174
204
|
*
|
|
175
205
|
* @returns `true` if any element satisfies the condition, `false` otherwise.
|
|
@@ -202,6 +232,9 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
202
232
|
* This means that the original iterator won't be consumed until the
|
|
203
233
|
* new one is and that consuming one of them will consume the other as well.
|
|
204
234
|
*
|
|
235
|
+
* ---
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
205
238
|
* ```ts
|
|
206
239
|
* const iterator = new SmartIterator<number>([-2, -1, 0, 1, 2]);
|
|
207
240
|
* const result = iterator.filter((value) => value < 0);
|
|
@@ -209,6 +242,8 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
209
242
|
* console.log(result.toArray()); // [-2, -1]
|
|
210
243
|
* ```
|
|
211
244
|
*
|
|
245
|
+
* ---
|
|
246
|
+
*
|
|
212
247
|
* @param predicate The condition to check for each element of the iterator.
|
|
213
248
|
*
|
|
214
249
|
* @returns A new {@link SmartIterator} containing only the elements that satisfy the condition.
|
|
@@ -228,6 +263,9 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
228
263
|
* This means that the original iterator won't be consumed until the
|
|
229
264
|
* new one is and that consuming one of them will consume the other as well.
|
|
230
265
|
*
|
|
266
|
+
* ---
|
|
267
|
+
*
|
|
268
|
+
* @example
|
|
231
269
|
* ```ts
|
|
232
270
|
* const iterator = new SmartIterator<number | string>([-2, "-1", "0", 1, "2"]);
|
|
233
271
|
* const result = iterator.filter<number>((value) => typeof value === "number");
|
|
@@ -235,6 +273,8 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
235
273
|
* console.log(result.toArray()); // [-2, 1]
|
|
236
274
|
* ```
|
|
237
275
|
*
|
|
276
|
+
* ---
|
|
277
|
+
*
|
|
238
278
|
* @template S
|
|
239
279
|
* The type of the elements that satisfy the condition.
|
|
240
280
|
* This allows the type-system to infer the correct type of the new iterator.
|
|
@@ -277,6 +317,9 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
277
317
|
* This means that the original iterator won't be consumed until the
|
|
278
318
|
* new one is and that consuming one of them will consume the other as well.
|
|
279
319
|
*
|
|
320
|
+
* ---
|
|
321
|
+
*
|
|
322
|
+
* @example
|
|
280
323
|
* ```ts
|
|
281
324
|
* const iterator = new SmartIterator<number>([-2, -1, 0, 1, 2]);
|
|
282
325
|
* const result = iterator.map((value) => Math.abs(value));
|
|
@@ -284,6 +327,8 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
284
327
|
* console.log(result.toArray()); // [2, 1, 0, 1, 2]
|
|
285
328
|
* ```
|
|
286
329
|
*
|
|
330
|
+
* ---
|
|
331
|
+
*
|
|
287
332
|
* @template V The type of the elements after the transformation.
|
|
288
333
|
*
|
|
289
334
|
* @param iteratee The transformation function to apply to each element of the iterator.
|
|
@@ -323,6 +368,9 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
323
368
|
* - If an empty iterator is provided, a {@link ValueException} will be thrown.
|
|
324
369
|
* - If the iterator is infinite, the method will never return.
|
|
325
370
|
*
|
|
371
|
+
* ---
|
|
372
|
+
*
|
|
373
|
+
* @example
|
|
326
374
|
* ```ts
|
|
327
375
|
* const iterator = new SmartIterator<number>([1, 2, 3, 4, 5]);
|
|
328
376
|
* const result = iterator.reduce((acc, value) => acc + value);
|
|
@@ -330,6 +378,8 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
330
378
|
* console.log(result); // 15
|
|
331
379
|
* ```
|
|
332
380
|
*
|
|
381
|
+
* ---
|
|
382
|
+
*
|
|
333
383
|
* @param reducer The reducer function to apply to each element of the iterator.
|
|
334
384
|
*
|
|
335
385
|
* @returns The final result of the reduction.
|
|
@@ -348,6 +398,9 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
348
398
|
*
|
|
349
399
|
* If the iterator is infinite, the method will never return.
|
|
350
400
|
*
|
|
401
|
+
* ---
|
|
402
|
+
*
|
|
403
|
+
* @example
|
|
351
404
|
* ```ts
|
|
352
405
|
* const iterator = new SmartIterator<number>([1, 2, 3, 4, 5]);
|
|
353
406
|
* const result = iterator.reduce((acc, value) => acc + value, 10);
|
|
@@ -355,6 +408,8 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
355
408
|
* console.log(result); // 25
|
|
356
409
|
* ```
|
|
357
410
|
*
|
|
411
|
+
* ---
|
|
412
|
+
*
|
|
358
413
|
* @template A The type of the accumulator value which will also be the type of the final result of the reduction.
|
|
359
414
|
*
|
|
360
415
|
* @param reducer The reducer function to apply to each element of the iterator.
|
|
@@ -400,6 +455,9 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
400
455
|
* This means that the original iterator won't be consumed until the
|
|
401
456
|
* new one is and that consuming one of them will consume the other as well.
|
|
402
457
|
*
|
|
458
|
+
* ---
|
|
459
|
+
*
|
|
460
|
+
* @example
|
|
403
461
|
* ```ts
|
|
404
462
|
* const iterator = new SmartIterator<number[]>([[-2, -1], 0, 1, 2, [3, 4, 5]]);
|
|
405
463
|
* const result = iterator.flatMap((value) => value);
|
|
@@ -407,6 +465,8 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
407
465
|
* console.log(result.toArray()); // [-2, -1, 0, 1, 2, 3, 4, 5]
|
|
408
466
|
* ```
|
|
409
467
|
*
|
|
468
|
+
* ---
|
|
469
|
+
*
|
|
410
470
|
* @template V The type of the elements after the transformation.
|
|
411
471
|
*
|
|
412
472
|
* @param iteratee The transformation function to apply to each element of the iterator.
|
|
@@ -452,6 +512,9 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
452
512
|
* Only the dropped elements will be consumed in the process.
|
|
453
513
|
* The rest of the iterator will be consumed only once the new one is.
|
|
454
514
|
*
|
|
515
|
+
* ---
|
|
516
|
+
*
|
|
517
|
+
* @example
|
|
455
518
|
* ```ts
|
|
456
519
|
* const iterator = new SmartIterator<number>([-2, -1, 0, 1, 2]);
|
|
457
520
|
* const result = iterator.drop(3);
|
|
@@ -459,6 +522,8 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
459
522
|
* console.log(result.toArray()); // [1, 2]
|
|
460
523
|
* ```
|
|
461
524
|
*
|
|
525
|
+
* ---
|
|
526
|
+
*
|
|
462
527
|
* @param count The number of elements to drop.
|
|
463
528
|
*
|
|
464
529
|
* @returns A new {@link SmartIterator} containing the remaining elements.
|
|
@@ -503,6 +568,9 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
503
568
|
* Only the taken elements will be consumed from the original iterator.
|
|
504
569
|
* The rest of the original iterator will be available for further consumption.
|
|
505
570
|
*
|
|
571
|
+
* ---
|
|
572
|
+
*
|
|
573
|
+
* @example
|
|
506
574
|
* ```ts
|
|
507
575
|
* const iterator = new SmartIterator<number>([-2, -1, 0, 1, 2]);
|
|
508
576
|
* const result = iterator.take(3);
|
|
@@ -511,6 +579,8 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
511
579
|
* console.log(iterator.toArray()); // [1, 2]
|
|
512
580
|
* ```
|
|
513
581
|
*
|
|
582
|
+
* ---
|
|
583
|
+
*
|
|
514
584
|
* @param limit The number of elements to take.
|
|
515
585
|
*
|
|
516
586
|
* @returns A new {@link SmartIterator} containing the taken elements.
|
|
@@ -550,6 +620,9 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
550
620
|
* - If no element satisfies the condition, `undefined` will be returned once the entire iterator is consumed.
|
|
551
621
|
* - If the iterator is infinite and no element satisfies the condition, the method will never return.
|
|
552
622
|
*
|
|
623
|
+
* ---
|
|
624
|
+
*
|
|
625
|
+
* @example
|
|
553
626
|
* ```ts
|
|
554
627
|
* const iterator = new SmartIterator<number>([-2, -1, 0, 1, 2]);
|
|
555
628
|
* const result = iterator.find((value) => value > 0);
|
|
@@ -557,6 +630,8 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
557
630
|
* console.log(result); // 1
|
|
558
631
|
* ```
|
|
559
632
|
*
|
|
633
|
+
* ---
|
|
634
|
+
*
|
|
560
635
|
* @param predicate The condition to check for each element of the iterator.
|
|
561
636
|
*
|
|
562
637
|
* @returns The first element that satisfies the condition, `undefined` otherwise.
|
|
@@ -577,6 +652,9 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
577
652
|
* - If no element satisfies the condition, `undefined` will be returned once the entire iterator is consumed.
|
|
578
653
|
* - If the iterator is infinite and no element satisfies the condition, the method will never return.
|
|
579
654
|
*
|
|
655
|
+
* ---
|
|
656
|
+
*
|
|
657
|
+
* @example
|
|
580
658
|
* ```ts
|
|
581
659
|
* const iterator = new SmartIterator<number | string>([-2, "-1", "0", 1, "2"]);
|
|
582
660
|
* const result = iterator.find<number>((value) => typeof value === "number");
|
|
@@ -584,6 +662,8 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
584
662
|
* console.log(result); // -2
|
|
585
663
|
* ```
|
|
586
664
|
*
|
|
665
|
+
* ---
|
|
666
|
+
*
|
|
587
667
|
* @template S
|
|
588
668
|
* The type of the element that satisfies the condition.
|
|
589
669
|
* This allows the type-system to infer the correct type of the result.
|
|
@@ -621,6 +701,9 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
621
701
|
* This means that the original iterator won't be consumed until the
|
|
622
702
|
* new one is and that consuming one of them will consume the other as well.
|
|
623
703
|
*
|
|
704
|
+
* ---
|
|
705
|
+
*
|
|
706
|
+
* @example
|
|
624
707
|
* ```ts
|
|
625
708
|
* const iterator = new SmartIterator<string>(["A", "M", "N", "Z"]);
|
|
626
709
|
* const result = iterator.enumerate();
|
|
@@ -628,6 +711,8 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
628
711
|
* console.log(result.toArray()); // [[0, "A"], [1, "M"], [2, "N"], [3, "Z"]]
|
|
629
712
|
* ```
|
|
630
713
|
*
|
|
714
|
+
* ---
|
|
715
|
+
*
|
|
631
716
|
* @returns A new {@link SmartIterator} containing the enumerated elements.
|
|
632
717
|
*/
|
|
633
718
|
public enumerate(): SmartIterator<[number, T], R>
|
|
@@ -646,6 +731,9 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
646
731
|
* This means that the original iterator won't be consumed until the
|
|
647
732
|
* new one is and that consuming one of them will consume the other as well.
|
|
648
733
|
*
|
|
734
|
+
* ---
|
|
735
|
+
*
|
|
736
|
+
* @example
|
|
649
737
|
* ```ts
|
|
650
738
|
* const iterator = new SmartIterator<number>([1, 1, 2, 3, 2, 3, 4, 5, 5, 4]);
|
|
651
739
|
* const result = iterator.unique();
|
|
@@ -653,6 +741,8 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
653
741
|
* console.log(result.toArray()); // [1, 2, 3, 4, 5]
|
|
654
742
|
* ```
|
|
655
743
|
*
|
|
744
|
+
* ---
|
|
745
|
+
*
|
|
656
746
|
* @returns A new {@link SmartIterator} containing only the unique elements.
|
|
657
747
|
*/
|
|
658
748
|
public unique(): SmartIterator<T, R>
|
|
@@ -680,6 +770,9 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
680
770
|
*
|
|
681
771
|
* If the iterator is infinite, the method will never return.
|
|
682
772
|
*
|
|
773
|
+
* ---
|
|
774
|
+
*
|
|
775
|
+
* @example
|
|
683
776
|
* ```ts
|
|
684
777
|
* const iterator = new SmartIterator<number>([1, 2, 3, 4, 5]);
|
|
685
778
|
* const result = iterator.count();
|
|
@@ -687,6 +780,8 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
687
780
|
* console.log(result); // 5
|
|
688
781
|
* ```
|
|
689
782
|
*
|
|
783
|
+
* ---
|
|
784
|
+
*
|
|
690
785
|
* @returns The number of elements in the iterator.
|
|
691
786
|
*/
|
|
692
787
|
public count(): number
|
|
@@ -709,6 +804,9 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
709
804
|
* This method will consume the entire iterator in the process.
|
|
710
805
|
* If the iterator is infinite, the method will never return.
|
|
711
806
|
*
|
|
807
|
+
* ---
|
|
808
|
+
*
|
|
809
|
+
* @example
|
|
712
810
|
* ```ts
|
|
713
811
|
* const iterator = new SmartIterator<number>(["A", "M", "N", "Z"]);
|
|
714
812
|
* iterator.forEach((value, index) =>
|
|
@@ -717,6 +815,8 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
717
815
|
* }
|
|
718
816
|
* ```
|
|
719
817
|
*
|
|
818
|
+
* ---
|
|
819
|
+
*
|
|
720
820
|
* @param iteratee The function to apply to each element of the iterator.
|
|
721
821
|
*/
|
|
722
822
|
public forEach(iteratee: Iteratee<T>): void
|
|
@@ -740,6 +840,9 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
740
840
|
*
|
|
741
841
|
* Once the iterator is done, the method will return an object with the `done` property set to `true`.
|
|
742
842
|
*
|
|
843
|
+
* ---
|
|
844
|
+
*
|
|
845
|
+
* @example
|
|
743
846
|
* ```ts
|
|
744
847
|
* const iterator = new SmartIterator<number>([1, 2, 3, 4, 5]);
|
|
745
848
|
*
|
|
@@ -754,6 +857,8 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
754
857
|
* console.log(result); // { done: true, value: undefined }
|
|
755
858
|
* ```
|
|
756
859
|
*
|
|
860
|
+
* ---
|
|
861
|
+
*
|
|
757
862
|
* @param values The value to pass to the next element, if required.
|
|
758
863
|
*
|
|
759
864
|
* @returns The result of the iteration, containing the value of the operation.
|
|
@@ -768,6 +873,9 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
768
873
|
* free the resources and perform any cleanup operation.
|
|
769
874
|
* It may also be used to signal the end or to compute a specific final result of the iteration process.
|
|
770
875
|
*
|
|
876
|
+
* ---
|
|
877
|
+
*
|
|
878
|
+
* @example
|
|
771
879
|
* ```ts
|
|
772
880
|
* const iterator = new SmartIterator<number>({
|
|
773
881
|
* _index: 0,
|
|
@@ -786,6 +894,8 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
786
894
|
* }
|
|
787
895
|
* ```
|
|
788
896
|
*
|
|
897
|
+
* ---
|
|
898
|
+
*
|
|
789
899
|
* @param value The final value of the iterator.
|
|
790
900
|
*
|
|
791
901
|
* @returns The result of the iterator.
|
|
@@ -802,6 +912,9 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
802
912
|
* free the resources and perform any cleanup operation.
|
|
803
913
|
* It may also be used to signal that an error occurred during the iteration process or to handle it.
|
|
804
914
|
*
|
|
915
|
+
* ---
|
|
916
|
+
*
|
|
917
|
+
* @example
|
|
805
918
|
* ```ts
|
|
806
919
|
* const iterator = new SmartIterator<number>({
|
|
807
920
|
* _index: 0,
|
|
@@ -829,6 +942,8 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
829
942
|
* }
|
|
830
943
|
* ```
|
|
831
944
|
*
|
|
945
|
+
* ---
|
|
946
|
+
*
|
|
832
947
|
* @param error The error to throw into the iterator.
|
|
833
948
|
*
|
|
834
949
|
* @returns The final result of the iterator.
|
|
@@ -852,6 +967,9 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
852
967
|
* This means that the original iterator won't be consumed until the
|
|
853
968
|
* the new one is and that consuming one of them will consume the other as well.
|
|
854
969
|
*
|
|
970
|
+
* ---
|
|
971
|
+
*
|
|
972
|
+
* @example
|
|
855
973
|
* ```ts
|
|
856
974
|
* const iterator = new SmartIterator<number>([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
|
|
857
975
|
* const result = iterator.groupBy<string>((value) => value % 2 === 0 ? "even" : "odd");
|
|
@@ -859,6 +977,8 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
859
977
|
* console.log(result.toObject()); // { odd: [1, 3, 5, 7, 9], even: [2, 4, 6, 8, 10] }
|
|
860
978
|
* ```
|
|
861
979
|
*
|
|
980
|
+
* ---
|
|
981
|
+
*
|
|
862
982
|
* @template K The type of the keys used to group the elements.
|
|
863
983
|
*
|
|
864
984
|
* @param iteratee The key function to apply to each element of the iterator.
|
|
@@ -881,6 +1001,9 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
881
1001
|
*
|
|
882
1002
|
* If the iterator is infinite, the method will never return.
|
|
883
1003
|
*
|
|
1004
|
+
* ---
|
|
1005
|
+
*
|
|
1006
|
+
* @example
|
|
884
1007
|
* ```ts
|
|
885
1008
|
* const iterator = new SmartIterator(function* ()
|
|
886
1009
|
* {
|
|
@@ -891,6 +1014,8 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
891
1014
|
* console.log(result); // [0, 1, 2, 3, 4]
|
|
892
1015
|
* ```
|
|
893
1016
|
*
|
|
1017
|
+
* ---
|
|
1018
|
+
*
|
|
894
1019
|
* @returns The {@link Array} containing all elements of the iterator.
|
|
895
1020
|
*/
|
|
896
1021
|
public toArray(): T[]
|