@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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@byloth/core",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "An unopinionated collection of useful functions and classes that I use widely in all my projects. 🔧",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Core",
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"dist",
|
|
32
32
|
"src"
|
|
33
33
|
],
|
|
34
|
-
"main": "
|
|
35
|
-
"module": "
|
|
34
|
+
"main": "dist/core.umd.cjs",
|
|
35
|
+
"module": "dist/core.js",
|
|
36
36
|
"exports": {
|
|
37
37
|
".": {
|
|
38
38
|
"import": {
|
|
@@ -45,16 +45,17 @@
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
},
|
|
48
|
-
"types": "
|
|
48
|
+
"types": "src/index.ts",
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@byloth/eslint-config-typescript": "^3.1.0",
|
|
51
|
-
"@eslint/compat": "^1.2.
|
|
52
|
-
"@types/node": "^22.13.
|
|
51
|
+
"@eslint/compat": "^1.2.7",
|
|
52
|
+
"@types/node": "^22.13.11",
|
|
53
|
+
"eslint": "^9.23.0",
|
|
53
54
|
"husky": "^9.1.7",
|
|
54
55
|
"jsdom": "^26.0.0",
|
|
55
|
-
"typescript": "^5.
|
|
56
|
-
"vite": "^6.
|
|
57
|
-
"vitest": "^3.0.
|
|
56
|
+
"typescript": "^5.8.2",
|
|
57
|
+
"vite": "^6.2.2",
|
|
58
|
+
"vitest": "^3.0.9"
|
|
58
59
|
},
|
|
59
60
|
"scripts": {
|
|
60
61
|
"dev": "vite",
|
package/src/index.ts
CHANGED
|
@@ -52,10 +52,15 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
52
52
|
/**
|
|
53
53
|
* Initializes a new instance of the {@link AggregatedAsyncIterator} class.
|
|
54
54
|
*
|
|
55
|
+
* ---
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
55
58
|
* ```ts
|
|
56
59
|
* const iterator = new AggregatedAsyncIterator<string, number>([["A", 1], ["B", 2], ["A", 3], ["C", 4], ["B", 5]]);
|
|
57
60
|
* ```
|
|
58
61
|
*
|
|
62
|
+
* ---
|
|
63
|
+
*
|
|
59
64
|
* @param iterable The iterable to aggregate.
|
|
60
65
|
*/
|
|
61
66
|
public constructor(iterable: Iterable<[K, T]>);
|
|
@@ -63,11 +68,16 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
63
68
|
/**
|
|
64
69
|
* Initializes a new instance of the {@link AggregatedAsyncIterator} class.
|
|
65
70
|
*
|
|
71
|
+
* ---
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
66
74
|
* ```ts
|
|
67
75
|
* const elements = fetch([...]); // Promise<[["A", 1], ["B", 2], ["A", 3], ["C", 4], ["B", 5]]>
|
|
68
76
|
* const iterator = new AggregatedAsyncIterator<string, number>(elements);
|
|
69
77
|
* ```
|
|
70
78
|
*
|
|
79
|
+
* ---
|
|
80
|
+
*
|
|
71
81
|
* @param iterable The iterable to aggregate.
|
|
72
82
|
*/
|
|
73
83
|
public constructor(iterable: AsyncIterable<[K, T]>);
|
|
@@ -75,6 +85,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
75
85
|
/**
|
|
76
86
|
* Initializes a new instance of the {@link AggregatedAsyncIterator} class.
|
|
77
87
|
*
|
|
88
|
+
* ---
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
78
91
|
* ```ts
|
|
79
92
|
* import { Random } from "@byloth/core";
|
|
80
93
|
*
|
|
@@ -90,6 +103,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
90
103
|
* });
|
|
91
104
|
* ```
|
|
92
105
|
*
|
|
106
|
+
* ---
|
|
107
|
+
*
|
|
93
108
|
* @param iterator The iterator to aggregate.
|
|
94
109
|
*/
|
|
95
110
|
public constructor(iterator: Iterator<[K, T]>);
|
|
@@ -97,6 +112,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
97
112
|
/**
|
|
98
113
|
* Initializes a new instance of the {@link AggregatedAsyncIterator} class.
|
|
99
114
|
*
|
|
115
|
+
* ---
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
100
118
|
* ```ts
|
|
101
119
|
* import { Random } from "@byloth/core";
|
|
102
120
|
*
|
|
@@ -112,6 +130,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
112
130
|
* });
|
|
113
131
|
* ```
|
|
114
132
|
*
|
|
133
|
+
* ---
|
|
134
|
+
*
|
|
115
135
|
* @param iterator The iterator to aggregate.
|
|
116
136
|
*/
|
|
117
137
|
public constructor(iterator: AsyncIterator<[K, T]>);
|
|
@@ -119,6 +139,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
119
139
|
/**
|
|
120
140
|
* Initializes a new instance of the {@link AggregatedAsyncIterator} class.
|
|
121
141
|
*
|
|
142
|
+
* ---
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
122
145
|
* ```ts
|
|
123
146
|
* import { range, Random } from "@byloth/core";
|
|
124
147
|
*
|
|
@@ -131,6 +154,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
131
154
|
* });
|
|
132
155
|
* ```
|
|
133
156
|
*
|
|
157
|
+
* ---
|
|
158
|
+
*
|
|
134
159
|
* @param generatorFn The generator function to aggregate.
|
|
135
160
|
*/
|
|
136
161
|
public constructor(generatorFn: GeneratorFunction<[K, T]>);
|
|
@@ -138,6 +163,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
138
163
|
/**
|
|
139
164
|
* Initializes a new instance of the {@link AggregatedAsyncIterator} class.
|
|
140
165
|
*
|
|
166
|
+
* ---
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
141
169
|
* ```ts
|
|
142
170
|
* import { range, Random } from "@byloth/core";
|
|
143
171
|
*
|
|
@@ -150,6 +178,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
150
178
|
* });
|
|
151
179
|
* ```
|
|
152
180
|
*
|
|
181
|
+
* ---
|
|
182
|
+
*
|
|
153
183
|
* @param generatorFn The generator function to aggregate.
|
|
154
184
|
*/
|
|
155
185
|
public constructor(generatorFn: AsyncGeneratorFunction<[K, T]>);
|
|
@@ -157,10 +187,15 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
157
187
|
/**
|
|
158
188
|
* Initializes a new instance of the {@link AggregatedAsyncIterator} class.
|
|
159
189
|
*
|
|
190
|
+
* ---
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
160
193
|
* ```ts
|
|
161
194
|
* const iterator = new AggregatedAsyncIterator(asyncKeyedValues);
|
|
162
195
|
* ```
|
|
163
196
|
*
|
|
197
|
+
* ---
|
|
198
|
+
*
|
|
164
199
|
* @param argument The iterable, iterator or generator function to aggregate.
|
|
165
200
|
*/
|
|
166
201
|
public constructor(argument: MaybeAsyncIteratorLike<[K, T]> | MaybeAsyncGeneratorFunction<[K, T]>);
|
|
@@ -182,6 +217,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
182
217
|
* object that will contain all the boolean results for each group.
|
|
183
218
|
* If the iterator is infinite, the method will never return.
|
|
184
219
|
*
|
|
220
|
+
* ---
|
|
221
|
+
*
|
|
222
|
+
* @example
|
|
185
223
|
* ```ts
|
|
186
224
|
* const results = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
187
225
|
* .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -190,6 +228,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
190
228
|
* console.log(await results.toObject()); // { odd: false, even: true }
|
|
191
229
|
* ```
|
|
192
230
|
*
|
|
231
|
+
* ---
|
|
232
|
+
*
|
|
193
233
|
* @param predicate The condition to check for each element of the iterator.
|
|
194
234
|
*
|
|
195
235
|
* @returns
|
|
@@ -227,6 +267,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
227
267
|
* object that will contain all the boolean results for each group.
|
|
228
268
|
* If the iterator is infinite, the method will never return.
|
|
229
269
|
*
|
|
270
|
+
* ---
|
|
271
|
+
*
|
|
272
|
+
* @example
|
|
230
273
|
* ```ts
|
|
231
274
|
* const results = new SmartAsyncIterator<number>([-5, -4, -3, -2, -1, 0])
|
|
232
275
|
* .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -235,6 +278,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
235
278
|
* console.log(await results.toObject()); // { odd: false, even: true }
|
|
236
279
|
* ```
|
|
237
280
|
*
|
|
281
|
+
* ---
|
|
282
|
+
*
|
|
238
283
|
* @param predicate The condition to check for each element of the iterator.
|
|
239
284
|
*
|
|
240
285
|
* @returns
|
|
@@ -269,6 +314,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
269
314
|
* This means that the original iterator won't be consumed until the
|
|
270
315
|
* new one is and that consuming one of them will consume the other as well.
|
|
271
316
|
*
|
|
317
|
+
* ---
|
|
318
|
+
*
|
|
319
|
+
* @example
|
|
272
320
|
* ```ts
|
|
273
321
|
* const results = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
274
322
|
* .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -277,6 +325,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
277
325
|
* console.log(await results.toObject()); // { odd: [3, 5], even: [0, 2, 6, 8] }
|
|
278
326
|
* ```
|
|
279
327
|
*
|
|
328
|
+
* ---
|
|
329
|
+
*
|
|
280
330
|
* @param predicate The condition to check for each element of the iterator.
|
|
281
331
|
*
|
|
282
332
|
* @returns A new {@link AggregatedAsyncIterator} containing the elements that satisfy the condition.
|
|
@@ -293,6 +343,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
293
343
|
* This means that the original iterator won't be consumed until the
|
|
294
344
|
* new one is and that consuming one of them will consume the other as well.
|
|
295
345
|
*
|
|
346
|
+
* ---
|
|
347
|
+
*
|
|
348
|
+
* @example
|
|
296
349
|
* ```ts
|
|
297
350
|
* const results = new SmartAsyncIterator<number>([-3, "-1", 0, "2", "3", 5, 6, "8"])
|
|
298
351
|
* .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -301,6 +354,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
301
354
|
* console.log(await results.toObject()); // { odd: [-3, 5], even: [0, 6] }
|
|
302
355
|
* ```
|
|
303
356
|
*
|
|
357
|
+
* ---
|
|
358
|
+
*
|
|
304
359
|
* @template S
|
|
305
360
|
* The type of the elements that satisfy the condition.
|
|
306
361
|
* This allows the type-system to infer the correct type of the new iterator.
|
|
@@ -342,6 +397,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
342
397
|
* This means that the original iterator won't be consumed until the
|
|
343
398
|
* new one is and that consuming one of them will consume the other as well.
|
|
344
399
|
*
|
|
400
|
+
* ---
|
|
401
|
+
*
|
|
402
|
+
* @example
|
|
345
403
|
* ```ts
|
|
346
404
|
* const results = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
347
405
|
* .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -350,6 +408,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
350
408
|
* console.log(await results.toObject()); // { odd: [3, 1, 3, 5], even: [0, 2, 6, 8] }
|
|
351
409
|
* ```
|
|
352
410
|
*
|
|
411
|
+
* ---
|
|
412
|
+
*
|
|
353
413
|
* @template V The type of the elements after the transformation.
|
|
354
414
|
*
|
|
355
415
|
* @param iteratee The transformation function to apply to each element of the iterator.
|
|
@@ -387,6 +447,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
387
447
|
* object that will contain all the reduced results for each group.
|
|
388
448
|
* If the iterator is infinite, the method will never return.
|
|
389
449
|
*
|
|
450
|
+
* ---
|
|
451
|
+
*
|
|
452
|
+
* @example
|
|
390
453
|
* ```ts
|
|
391
454
|
* const results = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
392
455
|
* .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -395,6 +458,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
395
458
|
* console.log(await results.toObject()); // { odd: 4, even: 16 }
|
|
396
459
|
* ```
|
|
397
460
|
*
|
|
461
|
+
* ---
|
|
462
|
+
*
|
|
398
463
|
* @param reducer The reducer function to apply to each element of the iterator.
|
|
399
464
|
*
|
|
400
465
|
* @returns
|
|
@@ -416,6 +481,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
416
481
|
* object that will contain all the reduced results for each group.
|
|
417
482
|
* If the iterator is infinite, the method will never return.
|
|
418
483
|
*
|
|
484
|
+
* ---
|
|
485
|
+
*
|
|
486
|
+
* @example
|
|
419
487
|
* ```ts
|
|
420
488
|
* const results = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
421
489
|
* .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -424,6 +492,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
424
492
|
* console.log(await results.toObject()); // { odd: 4, even: 16 }
|
|
425
493
|
* ```
|
|
426
494
|
*
|
|
495
|
+
* ---
|
|
496
|
+
*
|
|
427
497
|
* @template A The type of the accumulator value which will also be the final result of the reduction.
|
|
428
498
|
*
|
|
429
499
|
* @param reducer The reducer function to apply to each element of the iterator.
|
|
@@ -449,6 +519,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
449
519
|
* object that will contain all the reduced results for each group.
|
|
450
520
|
* If the iterator is infinite, the method will never return.
|
|
451
521
|
*
|
|
522
|
+
* ---
|
|
523
|
+
*
|
|
524
|
+
* @example
|
|
452
525
|
* ```ts
|
|
453
526
|
* const results = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
454
527
|
* .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -457,6 +530,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
457
530
|
* console.log(await results.toObject()); // { odd: { value: 4 }, even: { value: 16 } }
|
|
458
531
|
* ```
|
|
459
532
|
*
|
|
533
|
+
* ---
|
|
534
|
+
*
|
|
460
535
|
* @template A The type of the accumulator value which will also be the final result of the reduction.
|
|
461
536
|
*
|
|
462
537
|
* @param reducer The reducer function to apply to each element of the iterator.
|
|
@@ -515,6 +590,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
515
590
|
* This means that the original iterator won't be consumed until the
|
|
516
591
|
* new one is and that consuming one of them will consume the other as well.
|
|
517
592
|
*
|
|
593
|
+
* ---
|
|
594
|
+
*
|
|
595
|
+
* @example
|
|
518
596
|
* ```ts
|
|
519
597
|
* const results = new SmartAsyncIterator<number>([[-3, -1], 0, 2, 3, 5, [6, 8]])
|
|
520
598
|
* .groupBy(async (values) =>
|
|
@@ -527,6 +605,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
527
605
|
* console.log(await results.toObject()); // { odd: [-3, -1, 3, 5], even: [0, 2, 6, 8] }
|
|
528
606
|
* ```
|
|
529
607
|
*
|
|
608
|
+
* ---
|
|
609
|
+
*
|
|
530
610
|
* @template V The type of the elements after the transformation.
|
|
531
611
|
*
|
|
532
612
|
* @param iteratee The transformation function to apply to each element of the iterator.
|
|
@@ -568,6 +648,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
568
648
|
* This means that the original iterator won't be consumed until the
|
|
569
649
|
* new one is and that consuming one of them will consume the other as well.
|
|
570
650
|
*
|
|
651
|
+
* ---
|
|
652
|
+
*
|
|
653
|
+
* @example
|
|
571
654
|
* ```ts
|
|
572
655
|
* const results = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
573
656
|
* .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -576,6 +659,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
576
659
|
* console.log(await results.toObject()); // { odd: [3, 5], even: [6, 8] }
|
|
577
660
|
* ```
|
|
578
661
|
*
|
|
662
|
+
* ---
|
|
663
|
+
*
|
|
579
664
|
* @param count The number of elements to drop from the beginning of each group.
|
|
580
665
|
*
|
|
581
666
|
* @returns A new {@link AggregatedAsyncIterator} containing the remaining elements.
|
|
@@ -614,6 +699,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
614
699
|
* This means that the original iterator won't be consumed until the
|
|
615
700
|
* new one is and that consuming one of them will consume the other as well.
|
|
616
701
|
*
|
|
702
|
+
* ---
|
|
703
|
+
*
|
|
704
|
+
* @example
|
|
617
705
|
* ```ts
|
|
618
706
|
* const results = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
619
707
|
* .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -622,7 +710,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
622
710
|
* console.log(await results.toObject()); // { odd: [-3, -1], even: [0, 2] }
|
|
623
711
|
* ```
|
|
624
712
|
*
|
|
625
|
-
*
|
|
713
|
+
* ---
|
|
714
|
+
*
|
|
715
|
+
* @param limit The number of elements to take from the beginning of each group.
|
|
626
716
|
*
|
|
627
717
|
* @returns A new {@link AggregatedAsyncIterator} containing the taken elements.
|
|
628
718
|
*/
|
|
@@ -657,6 +747,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
657
747
|
* object that will contain the first element that satisfies the condition for each group.
|
|
658
748
|
* If the iterator is infinite, the method will never return.
|
|
659
749
|
*
|
|
750
|
+
* ---
|
|
751
|
+
*
|
|
752
|
+
* @example
|
|
660
753
|
* ```ts
|
|
661
754
|
* const results = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
662
755
|
* .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -665,6 +758,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
665
758
|
* console.log(await results.toObject()); // { odd: 3, even: 2 }
|
|
666
759
|
* ```
|
|
667
760
|
*
|
|
761
|
+
* ---
|
|
762
|
+
*
|
|
668
763
|
* @param predicate The condition to check for each element of the iterator.
|
|
669
764
|
*
|
|
670
765
|
* @returns
|
|
@@ -685,6 +780,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
685
780
|
* object that will contain the first element that satisfies the condition for each group.
|
|
686
781
|
* If the iterator is infinite, the method will never return.
|
|
687
782
|
*
|
|
783
|
+
* ---
|
|
784
|
+
*
|
|
785
|
+
* @example
|
|
688
786
|
* ```ts
|
|
689
787
|
* const results = new SmartAsyncIterator<number | string>([-3, "-1", 0, "2", "3", 5, 6, "8"])
|
|
690
788
|
* .groupBy(async (value) => Number(value) % 2 === 0 ? "even" : "odd")
|
|
@@ -693,6 +791,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
693
791
|
* console.log(await results.toObject()); // { odd: -3, even: 0 }
|
|
694
792
|
* ```
|
|
695
793
|
*
|
|
794
|
+
* ---
|
|
795
|
+
*
|
|
696
796
|
* @template S
|
|
697
797
|
* The type of the elements that satisfy the condition.
|
|
698
798
|
* This allows the type-system to infer the correct type of the new iterator.
|
|
@@ -739,6 +839,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
739
839
|
* This means that the original iterator won't be consumed until the
|
|
740
840
|
* new one is and that consuming one of them will consume the other as well.
|
|
741
841
|
*
|
|
842
|
+
* ---
|
|
843
|
+
*
|
|
844
|
+
* @example
|
|
742
845
|
* ```ts
|
|
743
846
|
* const results = new SmartAsyncIterator<number>([-3, 0, 2, -1, 3])
|
|
744
847
|
* .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -747,6 +850,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
747
850
|
* console.log(results.toObject()); // { odd: [[0, -3], [1, -1], [2, 3]], even: [[0, 0], [1, 2]] }
|
|
748
851
|
* ```
|
|
749
852
|
*
|
|
853
|
+
* ---
|
|
854
|
+
*
|
|
750
855
|
* @returns A new {@link AggregatedAsyncIterator} containing the enumerated elements.
|
|
751
856
|
*/
|
|
752
857
|
public enumerate(): AggregatedAsyncIterator<K, [number, T]>
|
|
@@ -765,6 +870,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
765
870
|
* This means that the original iterator won't be consumed until the
|
|
766
871
|
* new one is and that consuming one of them will consume the other as well.
|
|
767
872
|
*
|
|
873
|
+
* ---
|
|
874
|
+
*
|
|
875
|
+
* @example
|
|
768
876
|
* ```ts
|
|
769
877
|
* const results = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 6, -3, -1, 0, 5, 6, 8, 0, 2])
|
|
770
878
|
* .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -773,6 +881,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
773
881
|
* console.log(await results.toObject()); // { odd: [-3, -1, 3, 5], even: [0, 2, 6, 8] }
|
|
774
882
|
* ```
|
|
775
883
|
*
|
|
884
|
+
* ---
|
|
885
|
+
*
|
|
776
886
|
* @returns A new {@link AggregatedAsyncIterator} containing only the unique elements.
|
|
777
887
|
*/
|
|
778
888
|
public unique(): AggregatedAsyncIterator<K, T>
|
|
@@ -801,6 +911,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
801
911
|
*
|
|
802
912
|
* If the iterator is infinite, the method will never return.
|
|
803
913
|
*
|
|
914
|
+
* ---
|
|
915
|
+
*
|
|
916
|
+
* @example
|
|
804
917
|
* ```ts
|
|
805
918
|
* const results = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
806
919
|
* .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -809,6 +922,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
809
922
|
* console.log(await results.toObject()); // { odd: 4, even: 4 }
|
|
810
923
|
* ```
|
|
811
924
|
*
|
|
925
|
+
* ---
|
|
926
|
+
*
|
|
812
927
|
* @returns
|
|
813
928
|
* A {@link Promise} resolving to a new {@link ReducedIterator} containing the number of elements for each group.
|
|
814
929
|
*/
|
|
@@ -836,6 +951,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
836
951
|
* This method will consume the entire iterator in the process.
|
|
837
952
|
* If the iterator is infinite, the method will never return.
|
|
838
953
|
*
|
|
954
|
+
* ---
|
|
955
|
+
*
|
|
956
|
+
* @example
|
|
839
957
|
* ```ts
|
|
840
958
|
* const aggregator = new SmartAsyncIterator<number>([-3, 0, 2, -1, 3])
|
|
841
959
|
* .groupBy(async (value) => value % 2 === 0 ? "even" : "odd");
|
|
@@ -846,6 +964,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
846
964
|
* };
|
|
847
965
|
* ```
|
|
848
966
|
*
|
|
967
|
+
* ---
|
|
968
|
+
*
|
|
849
969
|
* @param iteratee The function to execute for each element of the iterator.
|
|
850
970
|
*
|
|
851
971
|
* @returns A {@link Promise} that will resolve once the iteration is complete.
|
|
@@ -875,6 +995,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
875
995
|
* This means that the original iterator won't be consumed until the
|
|
876
996
|
* new one is and that consuming one of them will consume the other as well.
|
|
877
997
|
*
|
|
998
|
+
* ---
|
|
999
|
+
*
|
|
1000
|
+
* @example
|
|
878
1001
|
* ```ts
|
|
879
1002
|
* const results = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
880
1003
|
* .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -884,6 +1007,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
884
1007
|
* console.log(await results.toObject()); // { "+": [1, 0, 3, 6], "-": [-3, -2, -5, -8] }
|
|
885
1008
|
* ```
|
|
886
1009
|
*
|
|
1010
|
+
* ---
|
|
1011
|
+
*
|
|
887
1012
|
* @template J The type of the new key.
|
|
888
1013
|
*
|
|
889
1014
|
* @param iteratee The function to determine the new key for each element of the iterator.
|
|
@@ -919,6 +1044,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
919
1044
|
* This means that the original iterator won't be consumed until the
|
|
920
1045
|
* new one is and that consuming one of them will consume the other as well.
|
|
921
1046
|
*
|
|
1047
|
+
* ---
|
|
1048
|
+
*
|
|
1049
|
+
* @example
|
|
922
1050
|
* ```ts
|
|
923
1051
|
* const keys = new SmartAsyncIterator([-3, Symbol(), "A", { }, null, [1 , 2, 3], false])
|
|
924
1052
|
* .groupBy(async (value) => typeof value)
|
|
@@ -927,6 +1055,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
927
1055
|
* console.log(await keys.toArray()); // ["number", "symbol", "string", "object", "boolean"]
|
|
928
1056
|
* ```
|
|
929
1057
|
*
|
|
1058
|
+
* ---
|
|
1059
|
+
*
|
|
930
1060
|
* @returns A new {@link SmartAsyncIterator} containing all the keys of the iterator.
|
|
931
1061
|
*/
|
|
932
1062
|
public keys(): SmartAsyncIterator<K>
|
|
@@ -958,6 +1088,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
958
1088
|
* This means that the original iterator won't be consumed until the
|
|
959
1089
|
* new one is and that consuming one of them will consume the other as well.
|
|
960
1090
|
*
|
|
1091
|
+
* ---
|
|
1092
|
+
*
|
|
1093
|
+
* @example
|
|
961
1094
|
* ```ts
|
|
962
1095
|
* const entries = new SmartAsyncIterator<number>([-3, 0, 2, -1, 3])
|
|
963
1096
|
* .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -966,6 +1099,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
966
1099
|
* console.log(await entries.toArray()); // [["odd", -3], ["even", 0], ["even", 2], ["odd", -1], ["odd", 3]]
|
|
967
1100
|
* ```
|
|
968
1101
|
*
|
|
1102
|
+
* ---
|
|
1103
|
+
*
|
|
969
1104
|
* @returns A new {@link SmartAsyncIterator} containing all the entries of the iterator.
|
|
970
1105
|
*/
|
|
971
1106
|
public entries(): SmartAsyncIterator<[K, T]>
|
|
@@ -984,6 +1119,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
984
1119
|
* This means that the original iterator won't be consumed until the
|
|
985
1120
|
* new one is and that consuming one of them will consume the other as well.
|
|
986
1121
|
*
|
|
1122
|
+
* ---
|
|
1123
|
+
*
|
|
1124
|
+
* @example
|
|
987
1125
|
* ```ts
|
|
988
1126
|
* const values = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
989
1127
|
* .groupBy(async (value) => value % 2 === 0 ? "even" : "odd")
|
|
@@ -992,6 +1130,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
992
1130
|
* console.log(await values.toArray()); // [-3, -1, 0, 2, 3, 5, 6, 8]
|
|
993
1131
|
* ```
|
|
994
1132
|
*
|
|
1133
|
+
* ---
|
|
1134
|
+
*
|
|
995
1135
|
* @returns A new {@link SmartAsyncIterator} containing all the values of the iterator.
|
|
996
1136
|
*/
|
|
997
1137
|
public values(): SmartAsyncIterator<T>
|
|
@@ -1010,6 +1150,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
1010
1150
|
*
|
|
1011
1151
|
* If the iterator is infinite, the method will never return.
|
|
1012
1152
|
*
|
|
1153
|
+
* ---
|
|
1154
|
+
*
|
|
1155
|
+
* @example
|
|
1013
1156
|
* ```ts
|
|
1014
1157
|
* const aggregator = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
1015
1158
|
* .groupBy(async (value) => value % 2 === 0 ? "even" : "odd");
|
|
@@ -1017,6 +1160,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
1017
1160
|
* console.log(await aggregator.toArray()); // [[-3, -1, 3, 5], [0, 2, 6, 8]]
|
|
1018
1161
|
* ```
|
|
1019
1162
|
*
|
|
1163
|
+
* ---
|
|
1164
|
+
*
|
|
1020
1165
|
* @returns A {@link Promise} resolving to an {@link Array} containing all the values of the iterator.
|
|
1021
1166
|
*/
|
|
1022
1167
|
public async toArray(): Promise<T[][]>
|
|
@@ -1032,6 +1177,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
1032
1177
|
*
|
|
1033
1178
|
* If the iterator is infinite, the method will never return.
|
|
1034
1179
|
*
|
|
1180
|
+
* ---
|
|
1181
|
+
*
|
|
1182
|
+
* @example
|
|
1035
1183
|
* ```ts
|
|
1036
1184
|
* const aggregator = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
1037
1185
|
* .groupBy(async (value) => value % 2 === 0 ? "even" : "odd");
|
|
@@ -1039,6 +1187,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
1039
1187
|
* console.log(await aggregator.toMap()); // Map(2) { "odd" => [-3, -1, 3, 5], "even" => [0, 2, 6, 8] }
|
|
1040
1188
|
* ```
|
|
1041
1189
|
*
|
|
1190
|
+
* ---
|
|
1191
|
+
*
|
|
1042
1192
|
* @returns A {@link Promise} resolving to a {@link Map} containing all the entries of the iterator.
|
|
1043
1193
|
*/
|
|
1044
1194
|
public async toMap(): Promise<Map<K, T[]>>
|
|
@@ -1062,6 +1212,9 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
1062
1212
|
*
|
|
1063
1213
|
* If the iterator is infinite, the method will never return.
|
|
1064
1214
|
*
|
|
1215
|
+
* ---
|
|
1216
|
+
*
|
|
1217
|
+
* @example
|
|
1065
1218
|
* ```ts
|
|
1066
1219
|
* const aggregator = new SmartAsyncIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])
|
|
1067
1220
|
* .groupBy(async (value) => value % 2 === 0 ? "even" : "odd");
|
|
@@ -1069,6 +1222,8 @@ export default class AggregatedAsyncIterator<K extends PropertyKey, T>
|
|
|
1069
1222
|
* console.log(await aggregator.toObject()); // { odd: [-3, -1, 3, 5], even: [0, 2, 6, 8] }
|
|
1070
1223
|
* ```
|
|
1071
1224
|
*
|
|
1225
|
+
* ---
|
|
1226
|
+
*
|
|
1072
1227
|
* @returns A {@link Promise} resolving to an object containing all the entries of the iterator.
|
|
1073
1228
|
*/
|
|
1074
1229
|
public async toObject(): Promise<Record<K, T[]>>
|