@byloth/core 2.0.0 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/core.js +900 -187
- package/dist/core.js.map +1 -1
- package/dist/core.umd.cjs +2 -2
- package/dist/core.umd.cjs.map +1 -1
- package/package.json +13 -10
- package/src/core/types.ts +43 -10
- package/src/index.ts +3 -2
- package/src/models/aggregators/aggregated-async-iterator.ts +161 -1
- package/src/models/aggregators/aggregated-iterator.ts +146 -1
- package/src/models/aggregators/reduced-iterator.ts +148 -8
- package/src/models/aggregators/types.ts +35 -0
- package/src/models/callbacks/callable-object.ts +7 -0
- package/src/models/callbacks/publisher.ts +33 -8
- package/src/models/callbacks/switchable-callback.ts +102 -21
- package/src/models/callbacks/types.ts +32 -0
- package/src/models/exceptions/core.ts +29 -0
- package/src/models/exceptions/index.ts +105 -1
- package/src/models/iterators/smart-async-iterator.ts +145 -0
- package/src/models/iterators/smart-iterator.ts +130 -0
- package/src/models/iterators/types.ts +79 -1
- package/src/models/json/json-storage.ts +123 -0
- package/src/models/json/types.ts +1 -1
- package/src/models/promises/deferred-promise.ts +15 -0
- package/src/models/promises/smart-promise.ts +45 -0
- package/src/models/promises/timed-promise.ts +10 -0
- package/src/models/promises/types.ts +30 -0
- package/src/models/timers/clock.ts +21 -0
- package/src/models/timers/countdown.ts +30 -0
- package/src/models/timers/game-loop.ts +26 -0
- package/src/models/types.ts +1 -1
- package/src/utils/async.ts +15 -0
- package/src/utils/curve.ts +11 -1
- package/src/utils/date.ts +36 -6
- package/src/utils/dom.ts +5 -0
- package/src/utils/iterator.ts +40 -0
- package/src/utils/math.ts +15 -0
- package/src/utils/random.ts +34 -0
- package/src/utils/string.ts +5 -0
|
@@ -17,6 +17,9 @@ import type { GeneratorFunction, Iteratee, TypeGuardPredicate, Reducer, Iterator
|
|
|
17
17
|
* This allows to chain multiple transformations without
|
|
18
18
|
* the need to iterate over the elements multiple times.
|
|
19
19
|
*
|
|
20
|
+
* ---
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
20
23
|
* ```ts
|
|
21
24
|
* const result = new SmartIterator<number>(["-5", "-4", "-3", "-2", "-1", "0", "1", "2", "3", "4", "5"])
|
|
22
25
|
* .map(Number)
|
|
@@ -28,6 +31,8 @@ import type { GeneratorFunction, Iteratee, TypeGuardPredicate, Reducer, Iterator
|
|
|
28
31
|
* console.log(result); // 31
|
|
29
32
|
* ```
|
|
30
33
|
*
|
|
34
|
+
* ---
|
|
35
|
+
*
|
|
31
36
|
* @template T The type of elements in the iterator.
|
|
32
37
|
* @template R The type of the final result of the iterator. Default is `void`.
|
|
33
38
|
* @template N The type of the argument required by the `next` method. Default is `undefined`.
|
|
@@ -42,10 +47,15 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
42
47
|
/**
|
|
43
48
|
* Initializes a new instance of the {@link SmartIterator} class.
|
|
44
49
|
*
|
|
50
|
+
* ---
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
45
53
|
* ```ts
|
|
46
54
|
* const iterator = new SmartIterator<string>(["A", "B", "C"]);
|
|
47
55
|
* ```
|
|
48
56
|
*
|
|
57
|
+
* ---
|
|
58
|
+
*
|
|
49
59
|
* @param iterable The iterable object to wrap.
|
|
50
60
|
*/
|
|
51
61
|
public constructor(iterable: Iterable<T, R, N>);
|
|
@@ -53,6 +63,9 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
53
63
|
/**
|
|
54
64
|
* Initializes a new instance of the {@link SmartIterator} class.
|
|
55
65
|
*
|
|
66
|
+
* ---
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
56
69
|
* ```ts
|
|
57
70
|
* const iterator = new SmartIterator<number, void, number>({
|
|
58
71
|
* _sum: 0, _count: 0,
|
|
@@ -67,6 +80,8 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
67
80
|
* })
|
|
68
81
|
* ```
|
|
69
82
|
*
|
|
83
|
+
* ---
|
|
84
|
+
*
|
|
70
85
|
* @param iterator The iterator object to wrap.
|
|
71
86
|
*/
|
|
72
87
|
public constructor(iterator: Iterator<T, R, N>);
|
|
@@ -74,6 +89,9 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
74
89
|
/**
|
|
75
90
|
* Initializes a new instance of the {@link SmartIterator} class.
|
|
76
91
|
*
|
|
92
|
+
* ---
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
77
95
|
* ```ts
|
|
78
96
|
* const iterator = new SmartIterator<number>(function* ()
|
|
79
97
|
* {
|
|
@@ -81,6 +99,8 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
81
99
|
* });
|
|
82
100
|
* ```
|
|
83
101
|
*
|
|
102
|
+
* ---
|
|
103
|
+
*
|
|
84
104
|
* @param generatorFn The generator function to wrap.
|
|
85
105
|
*/
|
|
86
106
|
public constructor(generatorFn: GeneratorFunction<T, R, N>);
|
|
@@ -88,10 +108,15 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
88
108
|
/**
|
|
89
109
|
* Initializes a new instance of the {@link SmartIterator} class.
|
|
90
110
|
*
|
|
111
|
+
* ---
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
91
114
|
* ```ts
|
|
92
115
|
* const iterator = new SmartIterator(values);
|
|
93
116
|
* ```
|
|
94
117
|
*
|
|
118
|
+
* ---
|
|
119
|
+
*
|
|
95
120
|
* @param argument The iterable, iterator or generator function to wrap.
|
|
96
121
|
*/
|
|
97
122
|
public constructor(argument: IteratorLike<T, R, N> | GeneratorFunction<T, R, N>);
|
|
@@ -124,6 +149,9 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
124
149
|
*
|
|
125
150
|
* If the iterator is infinite and every element satisfies the condition, the method will never return.
|
|
126
151
|
*
|
|
152
|
+
* ---
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
127
155
|
* ```ts
|
|
128
156
|
* const iterator = new SmartIterator<number>([-2, -1, 0, 1, 2]);
|
|
129
157
|
* const result = iterator.every((value) => value < 0);
|
|
@@ -131,6 +159,8 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
131
159
|
* console.log(result); // false
|
|
132
160
|
* ```
|
|
133
161
|
*
|
|
162
|
+
* ---
|
|
163
|
+
*
|
|
134
164
|
* @param predicate The condition to check for each element of the iterator.
|
|
135
165
|
*
|
|
136
166
|
* @returns `true` if all elements satisfy the condition, `false` otherwise.
|
|
@@ -163,6 +193,9 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
163
193
|
*
|
|
164
194
|
* If the iterator is infinite and no element satisfies the condition, the method will never return.
|
|
165
195
|
*
|
|
196
|
+
* ---
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
166
199
|
* ```ts
|
|
167
200
|
* const iterator = new SmartIterator<number>([-2, -1, 0, 1, 2]);
|
|
168
201
|
* const result = iterator.some((value) => value < 0);
|
|
@@ -170,6 +203,8 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
170
203
|
* console.log(result); // true
|
|
171
204
|
* ```
|
|
172
205
|
*
|
|
206
|
+
* ---
|
|
207
|
+
*
|
|
173
208
|
* @param predicate The condition to check for each element of the iterator.
|
|
174
209
|
*
|
|
175
210
|
* @returns `true` if any element satisfies the condition, `false` otherwise.
|
|
@@ -202,6 +237,9 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
202
237
|
* This means that the original iterator won't be consumed until the
|
|
203
238
|
* new one is and that consuming one of them will consume the other as well.
|
|
204
239
|
*
|
|
240
|
+
* ---
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
205
243
|
* ```ts
|
|
206
244
|
* const iterator = new SmartIterator<number>([-2, -1, 0, 1, 2]);
|
|
207
245
|
* const result = iterator.filter((value) => value < 0);
|
|
@@ -209,6 +247,8 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
209
247
|
* console.log(result.toArray()); // [-2, -1]
|
|
210
248
|
* ```
|
|
211
249
|
*
|
|
250
|
+
* ---
|
|
251
|
+
*
|
|
212
252
|
* @param predicate The condition to check for each element of the iterator.
|
|
213
253
|
*
|
|
214
254
|
* @returns A new {@link SmartIterator} containing only the elements that satisfy the condition.
|
|
@@ -228,6 +268,9 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
228
268
|
* This means that the original iterator won't be consumed until the
|
|
229
269
|
* new one is and that consuming one of them will consume the other as well.
|
|
230
270
|
*
|
|
271
|
+
* ---
|
|
272
|
+
*
|
|
273
|
+
* @example
|
|
231
274
|
* ```ts
|
|
232
275
|
* const iterator = new SmartIterator<number | string>([-2, "-1", "0", 1, "2"]);
|
|
233
276
|
* const result = iterator.filter<number>((value) => typeof value === "number");
|
|
@@ -235,6 +278,8 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
235
278
|
* console.log(result.toArray()); // [-2, 1]
|
|
236
279
|
* ```
|
|
237
280
|
*
|
|
281
|
+
* ---
|
|
282
|
+
*
|
|
238
283
|
* @template S
|
|
239
284
|
* The type of the elements that satisfy the condition.
|
|
240
285
|
* This allows the type-system to infer the correct type of the new iterator.
|
|
@@ -277,6 +322,9 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
277
322
|
* This means that the original iterator won't be consumed until the
|
|
278
323
|
* new one is and that consuming one of them will consume the other as well.
|
|
279
324
|
*
|
|
325
|
+
* ---
|
|
326
|
+
*
|
|
327
|
+
* @example
|
|
280
328
|
* ```ts
|
|
281
329
|
* const iterator = new SmartIterator<number>([-2, -1, 0, 1, 2]);
|
|
282
330
|
* const result = iterator.map((value) => Math.abs(value));
|
|
@@ -284,6 +332,8 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
284
332
|
* console.log(result.toArray()); // [2, 1, 0, 1, 2]
|
|
285
333
|
* ```
|
|
286
334
|
*
|
|
335
|
+
* ---
|
|
336
|
+
*
|
|
287
337
|
* @template V The type of the elements after the transformation.
|
|
288
338
|
*
|
|
289
339
|
* @param iteratee The transformation function to apply to each element of the iterator.
|
|
@@ -323,6 +373,9 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
323
373
|
* - If an empty iterator is provided, a {@link ValueException} will be thrown.
|
|
324
374
|
* - If the iterator is infinite, the method will never return.
|
|
325
375
|
*
|
|
376
|
+
* ---
|
|
377
|
+
*
|
|
378
|
+
* @example
|
|
326
379
|
* ```ts
|
|
327
380
|
* const iterator = new SmartIterator<number>([1, 2, 3, 4, 5]);
|
|
328
381
|
* const result = iterator.reduce((acc, value) => acc + value);
|
|
@@ -330,6 +383,8 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
330
383
|
* console.log(result); // 15
|
|
331
384
|
* ```
|
|
332
385
|
*
|
|
386
|
+
* ---
|
|
387
|
+
*
|
|
333
388
|
* @param reducer The reducer function to apply to each element of the iterator.
|
|
334
389
|
*
|
|
335
390
|
* @returns The final result of the reduction.
|
|
@@ -348,6 +403,9 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
348
403
|
*
|
|
349
404
|
* If the iterator is infinite, the method will never return.
|
|
350
405
|
*
|
|
406
|
+
* ---
|
|
407
|
+
*
|
|
408
|
+
* @example
|
|
351
409
|
* ```ts
|
|
352
410
|
* const iterator = new SmartIterator<number>([1, 2, 3, 4, 5]);
|
|
353
411
|
* const result = iterator.reduce((acc, value) => acc + value, 10);
|
|
@@ -355,6 +413,8 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
355
413
|
* console.log(result); // 25
|
|
356
414
|
* ```
|
|
357
415
|
*
|
|
416
|
+
* ---
|
|
417
|
+
*
|
|
358
418
|
* @template A The type of the accumulator value which will also be the type of the final result of the reduction.
|
|
359
419
|
*
|
|
360
420
|
* @param reducer The reducer function to apply to each element of the iterator.
|
|
@@ -400,6 +460,9 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
400
460
|
* This means that the original iterator won't be consumed until the
|
|
401
461
|
* new one is and that consuming one of them will consume the other as well.
|
|
402
462
|
*
|
|
463
|
+
* ---
|
|
464
|
+
*
|
|
465
|
+
* @example
|
|
403
466
|
* ```ts
|
|
404
467
|
* const iterator = new SmartIterator<number[]>([[-2, -1], 0, 1, 2, [3, 4, 5]]);
|
|
405
468
|
* const result = iterator.flatMap((value) => value);
|
|
@@ -407,6 +470,8 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
407
470
|
* console.log(result.toArray()); // [-2, -1, 0, 1, 2, 3, 4, 5]
|
|
408
471
|
* ```
|
|
409
472
|
*
|
|
473
|
+
* ---
|
|
474
|
+
*
|
|
410
475
|
* @template V The type of the elements after the transformation.
|
|
411
476
|
*
|
|
412
477
|
* @param iteratee The transformation function to apply to each element of the iterator.
|
|
@@ -452,6 +517,9 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
452
517
|
* Only the dropped elements will be consumed in the process.
|
|
453
518
|
* The rest of the iterator will be consumed only once the new one is.
|
|
454
519
|
*
|
|
520
|
+
* ---
|
|
521
|
+
*
|
|
522
|
+
* @example
|
|
455
523
|
* ```ts
|
|
456
524
|
* const iterator = new SmartIterator<number>([-2, -1, 0, 1, 2]);
|
|
457
525
|
* const result = iterator.drop(3);
|
|
@@ -459,6 +527,8 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
459
527
|
* console.log(result.toArray()); // [1, 2]
|
|
460
528
|
* ```
|
|
461
529
|
*
|
|
530
|
+
* ---
|
|
531
|
+
*
|
|
462
532
|
* @param count The number of elements to drop.
|
|
463
533
|
*
|
|
464
534
|
* @returns A new {@link SmartIterator} containing the remaining elements.
|
|
@@ -503,6 +573,9 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
503
573
|
* Only the taken elements will be consumed from the original iterator.
|
|
504
574
|
* The rest of the original iterator will be available for further consumption.
|
|
505
575
|
*
|
|
576
|
+
* ---
|
|
577
|
+
*
|
|
578
|
+
* @example
|
|
506
579
|
* ```ts
|
|
507
580
|
* const iterator = new SmartIterator<number>([-2, -1, 0, 1, 2]);
|
|
508
581
|
* const result = iterator.take(3);
|
|
@@ -511,6 +584,8 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
511
584
|
* console.log(iterator.toArray()); // [1, 2]
|
|
512
585
|
* ```
|
|
513
586
|
*
|
|
587
|
+
* ---
|
|
588
|
+
*
|
|
514
589
|
* @param limit The number of elements to take.
|
|
515
590
|
*
|
|
516
591
|
* @returns A new {@link SmartIterator} containing the taken elements.
|
|
@@ -550,6 +625,9 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
550
625
|
* - If no element satisfies the condition, `undefined` will be returned once the entire iterator is consumed.
|
|
551
626
|
* - If the iterator is infinite and no element satisfies the condition, the method will never return.
|
|
552
627
|
*
|
|
628
|
+
* ---
|
|
629
|
+
*
|
|
630
|
+
* @example
|
|
553
631
|
* ```ts
|
|
554
632
|
* const iterator = new SmartIterator<number>([-2, -1, 0, 1, 2]);
|
|
555
633
|
* const result = iterator.find((value) => value > 0);
|
|
@@ -557,6 +635,8 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
557
635
|
* console.log(result); // 1
|
|
558
636
|
* ```
|
|
559
637
|
*
|
|
638
|
+
* ---
|
|
639
|
+
*
|
|
560
640
|
* @param predicate The condition to check for each element of the iterator.
|
|
561
641
|
*
|
|
562
642
|
* @returns The first element that satisfies the condition, `undefined` otherwise.
|
|
@@ -577,6 +657,9 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
577
657
|
* - If no element satisfies the condition, `undefined` will be returned once the entire iterator is consumed.
|
|
578
658
|
* - If the iterator is infinite and no element satisfies the condition, the method will never return.
|
|
579
659
|
*
|
|
660
|
+
* ---
|
|
661
|
+
*
|
|
662
|
+
* @example
|
|
580
663
|
* ```ts
|
|
581
664
|
* const iterator = new SmartIterator<number | string>([-2, "-1", "0", 1, "2"]);
|
|
582
665
|
* const result = iterator.find<number>((value) => typeof value === "number");
|
|
@@ -584,6 +667,8 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
584
667
|
* console.log(result); // -2
|
|
585
668
|
* ```
|
|
586
669
|
*
|
|
670
|
+
* ---
|
|
671
|
+
*
|
|
587
672
|
* @template S
|
|
588
673
|
* The type of the element that satisfies the condition.
|
|
589
674
|
* This allows the type-system to infer the correct type of the result.
|
|
@@ -621,6 +706,9 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
621
706
|
* This means that the original iterator won't be consumed until the
|
|
622
707
|
* new one is and that consuming one of them will consume the other as well.
|
|
623
708
|
*
|
|
709
|
+
* ---
|
|
710
|
+
*
|
|
711
|
+
* @example
|
|
624
712
|
* ```ts
|
|
625
713
|
* const iterator = new SmartIterator<string>(["A", "M", "N", "Z"]);
|
|
626
714
|
* const result = iterator.enumerate();
|
|
@@ -628,6 +716,8 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
628
716
|
* console.log(result.toArray()); // [[0, "A"], [1, "M"], [2, "N"], [3, "Z"]]
|
|
629
717
|
* ```
|
|
630
718
|
*
|
|
719
|
+
* ---
|
|
720
|
+
*
|
|
631
721
|
* @returns A new {@link SmartIterator} containing the enumerated elements.
|
|
632
722
|
*/
|
|
633
723
|
public enumerate(): SmartIterator<[number, T], R>
|
|
@@ -646,6 +736,9 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
646
736
|
* This means that the original iterator won't be consumed until the
|
|
647
737
|
* new one is and that consuming one of them will consume the other as well.
|
|
648
738
|
*
|
|
739
|
+
* ---
|
|
740
|
+
*
|
|
741
|
+
* @example
|
|
649
742
|
* ```ts
|
|
650
743
|
* const iterator = new SmartIterator<number>([1, 1, 2, 3, 2, 3, 4, 5, 5, 4]);
|
|
651
744
|
* const result = iterator.unique();
|
|
@@ -653,6 +746,8 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
653
746
|
* console.log(result.toArray()); // [1, 2, 3, 4, 5]
|
|
654
747
|
* ```
|
|
655
748
|
*
|
|
749
|
+
* ---
|
|
750
|
+
*
|
|
656
751
|
* @returns A new {@link SmartIterator} containing only the unique elements.
|
|
657
752
|
*/
|
|
658
753
|
public unique(): SmartIterator<T, R>
|
|
@@ -680,6 +775,9 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
680
775
|
*
|
|
681
776
|
* If the iterator is infinite, the method will never return.
|
|
682
777
|
*
|
|
778
|
+
* ---
|
|
779
|
+
*
|
|
780
|
+
* @example
|
|
683
781
|
* ```ts
|
|
684
782
|
* const iterator = new SmartIterator<number>([1, 2, 3, 4, 5]);
|
|
685
783
|
* const result = iterator.count();
|
|
@@ -687,6 +785,8 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
687
785
|
* console.log(result); // 5
|
|
688
786
|
* ```
|
|
689
787
|
*
|
|
788
|
+
* ---
|
|
789
|
+
*
|
|
690
790
|
* @returns The number of elements in the iterator.
|
|
691
791
|
*/
|
|
692
792
|
public count(): number
|
|
@@ -709,6 +809,9 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
709
809
|
* This method will consume the entire iterator in the process.
|
|
710
810
|
* If the iterator is infinite, the method will never return.
|
|
711
811
|
*
|
|
812
|
+
* ---
|
|
813
|
+
*
|
|
814
|
+
* @example
|
|
712
815
|
* ```ts
|
|
713
816
|
* const iterator = new SmartIterator<number>(["A", "M", "N", "Z"]);
|
|
714
817
|
* iterator.forEach((value, index) =>
|
|
@@ -717,6 +820,8 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
717
820
|
* }
|
|
718
821
|
* ```
|
|
719
822
|
*
|
|
823
|
+
* ---
|
|
824
|
+
*
|
|
720
825
|
* @param iteratee The function to apply to each element of the iterator.
|
|
721
826
|
*/
|
|
722
827
|
public forEach(iteratee: Iteratee<T>): void
|
|
@@ -740,6 +845,9 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
740
845
|
*
|
|
741
846
|
* Once the iterator is done, the method will return an object with the `done` property set to `true`.
|
|
742
847
|
*
|
|
848
|
+
* ---
|
|
849
|
+
*
|
|
850
|
+
* @example
|
|
743
851
|
* ```ts
|
|
744
852
|
* const iterator = new SmartIterator<number>([1, 2, 3, 4, 5]);
|
|
745
853
|
*
|
|
@@ -754,6 +862,8 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
754
862
|
* console.log(result); // { done: true, value: undefined }
|
|
755
863
|
* ```
|
|
756
864
|
*
|
|
865
|
+
* ---
|
|
866
|
+
*
|
|
757
867
|
* @param values The value to pass to the next element, if required.
|
|
758
868
|
*
|
|
759
869
|
* @returns The result of the iteration, containing the value of the operation.
|
|
@@ -768,6 +878,9 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
768
878
|
* free the resources and perform any cleanup operation.
|
|
769
879
|
* It may also be used to signal the end or to compute a specific final result of the iteration process.
|
|
770
880
|
*
|
|
881
|
+
* ---
|
|
882
|
+
*
|
|
883
|
+
* @example
|
|
771
884
|
* ```ts
|
|
772
885
|
* const iterator = new SmartIterator<number>({
|
|
773
886
|
* _index: 0,
|
|
@@ -786,6 +899,8 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
786
899
|
* }
|
|
787
900
|
* ```
|
|
788
901
|
*
|
|
902
|
+
* ---
|
|
903
|
+
*
|
|
789
904
|
* @param value The final value of the iterator.
|
|
790
905
|
*
|
|
791
906
|
* @returns The result of the iterator.
|
|
@@ -802,6 +917,9 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
802
917
|
* free the resources and perform any cleanup operation.
|
|
803
918
|
* It may also be used to signal that an error occurred during the iteration process or to handle it.
|
|
804
919
|
*
|
|
920
|
+
* ---
|
|
921
|
+
*
|
|
922
|
+
* @example
|
|
805
923
|
* ```ts
|
|
806
924
|
* const iterator = new SmartIterator<number>({
|
|
807
925
|
* _index: 0,
|
|
@@ -829,6 +947,8 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
829
947
|
* }
|
|
830
948
|
* ```
|
|
831
949
|
*
|
|
950
|
+
* ---
|
|
951
|
+
*
|
|
832
952
|
* @param error The error to throw into the iterator.
|
|
833
953
|
*
|
|
834
954
|
* @returns The final result of the iterator.
|
|
@@ -852,6 +972,9 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
852
972
|
* This means that the original iterator won't be consumed until the
|
|
853
973
|
* the new one is and that consuming one of them will consume the other as well.
|
|
854
974
|
*
|
|
975
|
+
* ---
|
|
976
|
+
*
|
|
977
|
+
* @example
|
|
855
978
|
* ```ts
|
|
856
979
|
* const iterator = new SmartIterator<number>([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
|
|
857
980
|
* const result = iterator.groupBy<string>((value) => value % 2 === 0 ? "even" : "odd");
|
|
@@ -859,6 +982,8 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
859
982
|
* console.log(result.toObject()); // { odd: [1, 3, 5, 7, 9], even: [2, 4, 6, 8, 10] }
|
|
860
983
|
* ```
|
|
861
984
|
*
|
|
985
|
+
* ---
|
|
986
|
+
*
|
|
862
987
|
* @template K The type of the keys used to group the elements.
|
|
863
988
|
*
|
|
864
989
|
* @param iteratee The key function to apply to each element of the iterator.
|
|
@@ -881,6 +1006,9 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
881
1006
|
*
|
|
882
1007
|
* If the iterator is infinite, the method will never return.
|
|
883
1008
|
*
|
|
1009
|
+
* ---
|
|
1010
|
+
*
|
|
1011
|
+
* @example
|
|
884
1012
|
* ```ts
|
|
885
1013
|
* const iterator = new SmartIterator(function* ()
|
|
886
1014
|
* {
|
|
@@ -891,6 +1019,8 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
|
|
|
891
1019
|
* console.log(result); // [0, 1, 2, 3, 4]
|
|
892
1020
|
* ```
|
|
893
1021
|
*
|
|
1022
|
+
* ---
|
|
1023
|
+
*
|
|
894
1024
|
* @returns The {@link Array} containing all elements of the iterator.
|
|
895
1025
|
*/
|
|
896
1026
|
public toArray(): T[]
|