semantic-typescript 0.5.3 → 0.7.0

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.
@@ -1,50 +1,60 @@
1
- import { useAnyMatch, useAllMatch, Collector, useCollect, useCount, useError, useFindAny, useFindAt, useFindFirst, useFindLast, useFindMaximum, useFindMinimum, useForEach, useGroup, useGroupBy, useJoin, useLog, useNoneMatch, usePartition, usePartitionBy, useReduce, useToArray, useToMap, useToSet, useWrite, useFrequency, useNumericAverage, useNumericVariance, useNumericStandardDeviation, useNumericMedian, useNumericMode, useNumericSummate, useBigIntAverage, useBigIntVariance, useBigIntMedian, useBigIntMode, useBigIntSummate } from "./collector";
2
- import { isBigInt, isCollectable, isCollector, isFunction, isIterable, isNumber, isObject, isSemantic, isString } from "./guard";
3
- import { useHash } from "./hash";
4
- import { useCompare, useToBigInt, useToNumber } from "./hook";
5
- import { AsyncCollectableSymbol, BigIntStatisticsSymbol, CollectableSymbol, NumericStatisticsSymbol, OrderedCollectableSymbol, SemanticSymbol, StatisticsSymbol, UnorderedCollectableSymbol, WindowCollectableSymbol } from "./symbol";
6
- import { invalidate, validate } from "./utility";
7
- export class Semantic {
1
+ import { useSynchronousAnyMatch, useSynchronousAllMatch, useSynchronousCollect, useSynchronousCount, useSynchronousError, useSynchronousFindAny, useSynchronousFindAt, useSynchronousFindFirst, useSynchronousFindLast, useSynchronousFindMaximum, useSynchronousFindMinimum, useSynchronousForEach, useSynchronousGroup, useSynchronousGroupBy, useSynchronousJoin, useSynchronousLog, useSynchronousNoneMatch, useSynchronousPartition, useSynchronousPartitionBy, useSynchronousReduce, useSynchronousToArray, useSynchronousToMap, useSynchronousToSet, useSynchronousWrite, useSynchronousFrequency, useSynchronousBigIntAverage, useSynchronousBigIntMedian, useSynchronousBigIntMode, useSynchronousBigIntSummate, useSynchronousBigIntVariance, useSynchronousNumericAverage, useSynchronousNumericMedian, useSynchronousNumericMode, useSynchronousNumericStandardDeviation, useSynchronousNumericSummate, useSynchronousNumericVariance } from "./collector";
2
+ import { isFunction, isSynchronousSemantic, isIterable, isNumber, isBigInt, isObject, isString, isSynchronousCollectable, isSynchronousCollector } from "../guard";
3
+ import { useHash } from "../hash";
4
+ import { useCompare, useToBigInt, useToNumber } from "../hook";
5
+ import { SynchronousOrderedCollectableSymbol, SynchronousBigIntStatisticsSymbol, SynchronousCollectableSymbol, SynchronousNumericStatisticsSymbol, SynchronousSemanticSymbol, SynchronousWindowCollectableSymbol, SynchronousUnorderedCollectableSymbol, SynchronousStatisticsSymbol } from "../symbol";
6
+ import { invalidate, validate } from "../utility";
7
+ import { SynchronousCollector } from "./collector";
8
+ export class SynchronousSemantic {
8
9
  generator;
9
- Semantic = SemanticSymbol;
10
+ SynchronousSemantic = SynchronousSemanticSymbol;
11
+ [Symbol.toStringTag] = "SynchronousSemantic";
10
12
  constructor(generator) {
11
- this.generator = generator;
12
- Object.defineProperties(this, {
13
- "Semantic": {
14
- value: SemanticSymbol,
15
- writable: false,
16
- enumerable: false,
17
- configurable: false
18
- },
19
- "generator": {
20
- value: generator,
21
- writable: false,
22
- enumerable: false,
23
- configurable: false
24
- }
25
- });
13
+ if (isFunction(generator)) {
14
+ this.generator = generator;
15
+ Object.defineProperties(this, {
16
+ "SynchronousSemantic": {
17
+ value: SynchronousSemanticSymbol,
18
+ writable: false,
19
+ enumerable: false,
20
+ configurable: false
21
+ },
22
+ "generator": {
23
+ value: generator,
24
+ writable: false,
25
+ enumerable: false,
26
+ configurable: false
27
+ }
28
+ });
29
+ }
30
+ else {
31
+ throw new TypeError("Invalid arguments.");
32
+ }
26
33
  }
27
- concat(other) {
28
- if (isSemantic(other)) {
29
- return new Semantic((accept, interrupt) => {
34
+ concat(argument) {
35
+ if (isSynchronousSemantic(argument)) {
36
+ return new SynchronousSemantic((accept, interrupt) => {
30
37
  try {
38
+ let other = argument;
39
+ let generator = other.source();
31
40
  let count = 0n;
32
- this.generator((element, index) => {
33
- accept(element, index);
41
+ this.generator((element) => {
42
+ accept(element, count);
34
43
  count++;
35
44
  }, interrupt);
36
- let otherGenerator = Reflect.has(other, "generator") ? Reflect.get(other, "generator") : () => { };
37
- otherGenerator((element, index) => {
38
- accept(element, index + count);
45
+ generator((element) => {
46
+ accept(element, count);
47
+ count++;
39
48
  }, interrupt);
40
49
  }
41
50
  catch (error) {
42
- throw new Error("Uncaught error on concatenation.");
51
+ throw error;
43
52
  }
44
53
  });
45
54
  }
46
- if (isIterable(other)) {
47
- return new Semantic((accept, interrupt) => {
55
+ if (isIterable(argument)) {
56
+ let other = argument;
57
+ return new SynchronousSemantic((accept, interrupt) => {
48
58
  try {
49
59
  let count = 0n;
50
60
  this.generator((element, index) => {
@@ -57,7 +67,7 @@ export class Semantic {
57
67
  }
58
68
  }
59
69
  catch (error) {
60
- throw new Error("Uncaught error on concatenation.");
70
+ throw error;
61
71
  }
62
72
  });
63
73
  }
@@ -65,7 +75,7 @@ export class Semantic {
65
75
  }
66
76
  distinct(argument1) {
67
77
  let keyExtractor = validate(argument1) ? argument1 : (element) => element;
68
- return new Semantic((accept, interrupt) => {
78
+ return new SynchronousSemantic((accept, interrupt) => {
69
79
  try {
70
80
  let set = new Set();
71
81
  this.generator((element, index) => {
@@ -77,28 +87,29 @@ export class Semantic {
77
87
  }, interrupt);
78
88
  }
79
89
  catch (error) {
80
- throw new Error("Uncaught error on distinct.");
90
+ throw error;
81
91
  }
82
92
  });
83
93
  }
84
94
  dropWhile(predicate) {
85
95
  if (isFunction(predicate)) {
86
- return new Semantic((accept, interrupt) => {
96
+ return new SynchronousSemantic((accept, interrupt) => {
87
97
  try {
88
- let dropping = true;
98
+ let count = -1n;
89
99
  this.generator((element, index) => {
90
- if (dropping) {
100
+ if (count === -1n) {
91
101
  if (!predicate(element, index)) {
92
- dropping = false;
93
- accept(element, index);
102
+ count++;
94
103
  }
95
- return;
96
104
  }
97
- accept(element, index);
105
+ else {
106
+ accept(element, count);
107
+ count++;
108
+ }
98
109
  }, interrupt);
99
110
  }
100
111
  catch (error) {
101
- throw new Error("Uncaught error on dropWhile.");
112
+ throw error;
102
113
  }
103
114
  });
104
115
  }
@@ -106,7 +117,7 @@ export class Semantic {
106
117
  }
107
118
  filter(predicate) {
108
119
  if (isFunction(predicate)) {
109
- return new Semantic((accept, interrupt) => {
120
+ return new SynchronousSemantic((accept, interrupt) => {
110
121
  try {
111
122
  this.generator((element, index) => {
112
123
  if (predicate(element, index)) {
@@ -115,7 +126,7 @@ export class Semantic {
115
126
  }, interrupt);
116
127
  }
117
128
  catch (error) {
118
- throw new Error("Uncaught error on filter.");
129
+ throw error;
119
130
  }
120
131
  });
121
132
  }
@@ -123,7 +134,7 @@ export class Semantic {
123
134
  }
124
135
  flat(mapper) {
125
136
  if (isFunction(mapper)) {
126
- return new Semantic((accept, interrupt) => {
137
+ return new SynchronousSemantic((accept, interrupt) => {
127
138
  try {
128
139
  let count = 0n;
129
140
  let stop = false;
@@ -136,7 +147,7 @@ export class Semantic {
136
147
  count++;
137
148
  }
138
149
  }
139
- else if (isSemantic(result)) {
150
+ else if (isSynchronousSemantic(result)) {
140
151
  result.generator((subElement) => {
141
152
  accept(subElement, count);
142
153
  stop = stop || interrupt(subElement, count);
@@ -146,7 +157,7 @@ export class Semantic {
146
157
  }, (element) => interrupt(element, count) || stop);
147
158
  }
148
159
  catch (error) {
149
- throw new Error("Uncaught error on flat.");
160
+ throw error;
150
161
  }
151
162
  });
152
163
  }
@@ -154,21 +165,21 @@ export class Semantic {
154
165
  }
155
166
  flatMap(mapper) {
156
167
  if (isFunction(mapper)) {
157
- return new Semantic((accept, interrupt) => {
168
+ return new SynchronousSemantic((accept, interrupt) => {
158
169
  try {
159
170
  let count = 0n;
160
171
  let stop = false;
161
172
  this.generator((element, index) => {
162
- let result = mapper(element, index);
163
- if (isIterable(result)) {
164
- for (let subElement of result) {
173
+ let transform = mapper(element, index);
174
+ if (isIterable(transform)) {
175
+ for (let subElement of transform) {
165
176
  accept(subElement, count);
166
177
  stop = stop || interrupt(subElement, count);
167
178
  count++;
168
179
  }
169
180
  }
170
- else if (isSemantic(result)) {
171
- result.generator((subElement) => {
181
+ else if (isSynchronousSemantic(transform)) {
182
+ transform.source()((subElement) => {
172
183
  accept(subElement, count);
173
184
  stop = stop || interrupt(subElement, count);
174
185
  count++;
@@ -177,44 +188,44 @@ export class Semantic {
177
188
  }, () => stop);
178
189
  }
179
190
  catch (error) {
180
- throw new Error("Uncaught error on flatMap.");
191
+ throw error;
181
192
  }
182
193
  });
183
194
  }
184
195
  throw new TypeError("Invalid arguments.");
185
196
  }
186
- limit(n) {
187
- if (isNumber(n)) {
188
- let limit = BigInt(n);
189
- return new Semantic((accept, interrupt) => {
197
+ limit(argument) {
198
+ if (isNumber(argument)) {
199
+ let limit = BigInt(argument);
200
+ return new SynchronousSemantic((accept, interrupt) => {
190
201
  try {
191
202
  let count = 0n;
192
- this.generator((element, index) => {
203
+ this.generator((element) => {
193
204
  if (count < limit) {
194
- accept(element, index);
205
+ accept(element, count);
195
206
  count++;
196
207
  }
197
- }, (element) => interrupt(element, count) || count >= limit);
208
+ }, (element, index) => interrupt(element, index) || count >= limit);
198
209
  }
199
210
  catch (error) {
200
- throw new Error("Uncaught error on limit.");
211
+ throw error;
201
212
  }
202
213
  });
203
214
  }
204
- if (isBigInt(n)) {
205
- let limit = n;
206
- return new Semantic((accept, interrupt) => {
215
+ if (isBigInt(argument)) {
216
+ let limit = argument;
217
+ return new SynchronousSemantic((accept, interrupt) => {
207
218
  try {
208
219
  let count = 0n;
209
- this.generator((element, index) => {
220
+ this.generator((element) => {
210
221
  if (count < limit) {
211
- accept(element, index);
222
+ accept(element, count);
212
223
  count++;
213
224
  }
214
- }, (element) => interrupt(element, count) || count >= limit);
225
+ }, (element, index) => interrupt(element, index) || count >= limit);
215
226
  }
216
227
  catch (error) {
217
- throw new Error("Uncaught error on limit.");
228
+ throw error;
218
229
  }
219
230
  });
220
231
  }
@@ -222,7 +233,7 @@ export class Semantic {
222
233
  }
223
234
  map(mapper) {
224
235
  if (isFunction(mapper)) {
225
- return new Semantic((accept, interrupt) => {
236
+ return new SynchronousSemantic((accept, interrupt) => {
226
237
  try {
227
238
  let stop = false;
228
239
  this.generator((element, index) => {
@@ -232,7 +243,7 @@ export class Semantic {
232
243
  }, () => stop);
233
244
  }
234
245
  catch (error) {
235
- throw new Error("Uncaught error on map.");
246
+ throw error;
236
247
  }
237
248
  });
238
249
  }
@@ -240,7 +251,7 @@ export class Semantic {
240
251
  }
241
252
  peek(consumer) {
242
253
  if (isFunction(consumer)) {
243
- return new Semantic((accept, interrupt) => {
254
+ return new SynchronousSemantic((accept, interrupt) => {
244
255
  try {
245
256
  this.generator((element, index) => {
246
257
  accept(element, index);
@@ -248,7 +259,7 @@ export class Semantic {
248
259
  }, interrupt);
249
260
  }
250
261
  catch (error) {
251
- throw new Error("Uncaught error on peek.");
262
+ throw error;
252
263
  }
253
264
  });
254
265
  }
@@ -256,58 +267,59 @@ export class Semantic {
256
267
  }
257
268
  redirect(redirector) {
258
269
  if (isFunction(redirector)) {
259
- return new Semantic((accept, interrupt) => {
270
+ return new SynchronousSemantic((accept, interrupt) => {
260
271
  try {
261
272
  this.generator((element, index) => {
262
273
  accept(element, redirector(element, index));
263
274
  }, interrupt);
264
275
  }
265
276
  catch (error) {
266
- throw new Error("Uncaught error on redirect.");
277
+ throw error;
267
278
  }
268
279
  });
269
280
  }
270
281
  throw new TypeError("Invalid arguments.");
271
282
  }
272
283
  reverse() {
273
- return new Semantic((accept, interrupt) => {
284
+ return new SynchronousSemantic((accept, interrupt) => {
274
285
  try {
275
286
  this.generator((element, index) => {
276
287
  accept(element, -index);
277
288
  }, interrupt);
278
289
  }
279
290
  catch (error) {
280
- throw new Error("Uncaught error on reverse.");
291
+ throw error;
281
292
  }
282
293
  });
283
294
  }
284
295
  shuffle(mapper) {
285
296
  if (isFunction(mapper)) {
286
- try {
287
- return new Semantic((accept, interrupt) => {
297
+ return new SynchronousSemantic((accept, interrupt) => {
298
+ try {
288
299
  this.generator((element, index) => {
289
300
  accept(element, mapper(element, index));
290
301
  }, interrupt);
291
- });
292
- }
293
- catch (error) {
294
- throw new Error("Uncaught error on shuffle.");
295
- }
302
+ }
303
+ catch (error) {
304
+ throw error;
305
+ }
306
+ });
296
307
  }
297
- return new Semantic((accept, interrupt) => {
308
+ return new SynchronousSemantic((accept, interrupt) => {
298
309
  try {
299
310
  this.generator((element, index) => {
300
311
  accept(element, useHash(element, index));
301
312
  }, interrupt);
302
313
  }
303
314
  catch (error) {
304
- throw new Error("Uncaught error on shuffle.");
315
+ throw error;
305
316
  }
306
317
  });
307
318
  }
308
- skip(n) {
309
- if (isNumber(n)) {
310
- return new Semantic((accept, interrupt) => {
319
+ skip(argument) {
320
+ if (isNumber(argument)) {
321
+ let n = argument;
322
+ return new SynchronousSemantic((accept, interrupt) => {
311
323
  try {
312
324
  let count = 0n;
313
325
  let limit = BigInt(n);
@@ -321,12 +333,13 @@ export class Semantic {
321
333
  }, interrupt);
322
334
  }
323
335
  catch (error) {
324
- throw new Error("Uncaught error on skip.");
336
+ throw error;
325
337
  }
326
338
  });
327
339
  }
328
- if (isBigInt(n)) {
329
- return new Semantic((accept, interrupt) => {
340
+ if (isBigInt(argument)) {
341
+ let n = argument;
342
+ return new SynchronousSemantic((accept, interrupt) => {
330
343
  try {
331
344
  let count = 0n;
332
345
  this.generator((element, index) => {
@@ -339,166 +352,152 @@ export class Semantic {
339
352
  }, interrupt);
340
353
  }
341
354
  catch (error) {
342
- throw new Error("Uncaught error on skip.");
355
+ throw error;
343
356
  }
344
357
  });
345
358
  }
346
359
  throw new TypeError("Invalid arguments.");
347
360
  }
348
- sorted(comparator) {
349
- if (isFunction(comparator)) {
350
- try {
351
- return new OrderedCollectable(this.generator, comparator);
352
- }
353
- catch (error) {
354
- throw new Error("Uncaught error on sorted.");
355
- }
356
- }
357
- try {
358
- return new OrderedCollectable(this.generator, (a, b) => useCompare(a, b));
359
- }
360
- catch (error) {
361
- throw new Error("Uncaught error on sorted.");
362
- }
361
+ source() {
362
+ return this.generator;
363
363
  }
364
364
  sub(start, end) {
365
- return new Semantic((accept, interrupt) => {
366
- try {
367
- let count = 0n;
368
- this.generator((element, index) => {
369
- if (count < end) {
370
- count++;
371
- if (count >= start) {
365
+ if ((isNumber(start) && isNumber(end)) || (isBigInt(start) && isBigInt(end))) {
366
+ return new SynchronousSemantic((accept, interrupt) => {
367
+ try {
368
+ let count = 0n;
369
+ let resolvedStart = useToBigInt(start);
370
+ let resolvedEnd = useToBigInt(end);
371
+ let minimum = resolvedStart < resolvedEnd ? resolvedStart : resolvedEnd;
372
+ let maximum = resolvedStart < resolvedEnd ? resolvedEnd : resolvedStart;
373
+ this.generator((element, index) => {
374
+ if (minimum <= count && count < maximum) {
372
375
  accept(element, index);
376
+ count++;
373
377
  }
374
- }
375
- }, interrupt);
376
- }
377
- catch (error) {
378
- throw new Error("Uncaught error on sub.");
379
- }
380
- });
378
+ }, (element, index) => count >= maximum || interrupt(element, index));
379
+ }
380
+ catch (error) {
381
+ throw error;
382
+ }
383
+ });
384
+ }
385
+ throw new TypeError("Invalid arguments.");
381
386
  }
382
387
  takeWhile(predicate) {
383
- return new Semantic((accept, interrupt) => {
388
+ return new SynchronousSemantic((accept, interrupt) => {
384
389
  try {
390
+ let stop = false;
385
391
  this.generator((element, index) => {
386
- if (!predicate(element, index)) {
387
- interrupt(element, index);
388
- return;
392
+ if (predicate(element, index) && stop === false) {
393
+ accept(element, index);
389
394
  }
390
- accept(element, index);
391
- }, interrupt);
395
+ else {
396
+ stop = true;
397
+ }
398
+ }, (element, index) => stop || interrupt(element, index));
392
399
  }
393
400
  catch (error) {
394
- throw new Error("Uncaught error on takeWhile.");
401
+ throw error;
395
402
  }
396
403
  });
397
404
  }
398
405
  toCollectable(mapper) {
399
406
  if (isFunction(mapper)) {
400
407
  try {
401
- let collectable = mapper(this.generator);
402
- if (isCollectable(collectable)) {
403
- return collectable;
408
+ let SynchronousCollectable = mapper(this.generator);
409
+ if (isSynchronousCollectable(SynchronousCollectable)) {
410
+ return SynchronousCollectable;
404
411
  }
405
412
  }
406
413
  catch (error) {
407
- throw new Error("Uncaught error on toCollectable.");
414
+ throw error;
408
415
  }
409
416
  }
410
417
  try {
411
- return new UnorderedCollectable(this.generator);
418
+ return new SynchronousUnorderedCollectable(this.generator);
412
419
  }
413
420
  catch (error) {
414
- throw new Error("Uncaught error on toCollectable.");
421
+ throw error;
415
422
  }
416
423
  }
417
424
  toBigintStatistics() {
418
425
  try {
419
- return new BigIntStatistics(this.generator);
420
- }
421
- catch (error) {
422
- throw new Error("Uncaught error on toBigintStatistics.");
423
- }
424
- }
425
- toEvent() {
426
- try {
427
- return new EventCollectable(this.generator);
426
+ return new SynchronousBigIntStatistics(this.generator);
428
427
  }
429
428
  catch (error) {
430
- throw new Error("Uncaught error on toEvent.");
429
+ throw error;
431
430
  }
432
431
  }
433
432
  toNumericStatistics() {
434
433
  try {
435
- return new NumericStatistics(this.generator);
434
+ return new SynchronousNumericStatistics(this.generator);
436
435
  }
437
436
  catch (error) {
438
- throw new Error("Uncaught error on toNumericStatistics.");
437
+ throw error;
439
438
  }
440
439
  }
441
440
  toOrdered() {
442
441
  try {
443
- return new OrderedCollectable(this.generator);
442
+ return new SynchronousOrderedCollectable(this.generator);
444
443
  }
445
444
  catch (error) {
446
- throw new Error("Uncaught error on toOrdered.");
445
+ throw error;
447
446
  }
448
447
  }
449
448
  toUnordered() {
450
449
  try {
451
- return new UnorderedCollectable(this.generator);
450
+ return new SynchronousUnorderedCollectable(this.generator);
452
451
  }
453
452
  catch (error) {
454
- throw new Error(String(error));
453
+ throw error;
455
454
  }
456
455
  }
457
456
  toWindow() {
458
457
  try {
459
- return new WindowCollectable(this.generator);
458
+ return new SynchronousWindowCollectable(this.generator);
460
459
  }
461
460
  catch (error) {
462
- throw new Error("Uncaught error on toWindow.");
461
+ throw error;
463
462
  }
464
463
  }
465
464
  translate(argument1) {
466
465
  if (isNumber(argument1)) {
467
466
  let offset = argument1;
468
- return new Semantic((accept, interrupt) => {
467
+ return new SynchronousSemantic((accept, interrupt) => {
469
468
  try {
470
469
  this.generator((element, index) => {
471
470
  accept(element, index + BigInt(offset));
472
471
  }, interrupt);
473
472
  }
474
473
  catch (error) {
475
- throw new Error("Uncaught error on translate.");
474
+ throw error;
476
475
  }
477
476
  });
478
477
  }
479
478
  else if (isBigInt(argument1)) {
480
479
  let offset = argument1;
481
- return new Semantic((accept, interrupt) => {
480
+ return new SynchronousSemantic((accept, interrupt) => {
482
481
  try {
483
482
  this.generator((element, index) => {
484
483
  accept(element, index + offset);
485
484
  }, interrupt);
486
485
  }
487
486
  catch (error) {
488
- throw new Error("Uncaught error on translate.");
487
+ throw error;
489
488
  }
490
489
  });
491
490
  }
492
491
  else if (isFunction(argument1)) {
493
492
  let translator = argument1;
494
- return new Semantic((accept, interrupt) => {
493
+ return new SynchronousSemantic((accept, interrupt) => {
495
494
  try {
496
495
  this.generator((element, index) => {
497
496
  accept(element, index + translator(element, index));
498
497
  }, interrupt);
499
498
  }
500
499
  catch (error) {
501
- throw new Error("Uncaught error on translate.");
500
+ throw error;
502
501
  }
503
502
  });
504
503
  }
@@ -506,74 +505,80 @@ export class Semantic {
506
505
  }
507
506
  }
508
507
  ;
509
- export class Collectable {
510
- Collectable = CollectableSymbol;
508
+ export class SynchronousCollectable {
509
+ SynchronousCollectable = SynchronousCollectableSymbol;
510
+ [Symbol.toStringTag] = "SynchronousCollectable";
511
511
  constructor() {
512
- Object.defineProperty(this, "Collectable", {
513
- value: CollectableSymbol,
512
+ Object.defineProperty(this, "SynchronousCollectable", {
513
+ value: SynchronousCollectableSymbol,
514
514
  enumerable: false,
515
515
  writable: false,
516
516
  configurable: false
517
517
  });
518
518
  }
519
+ *[Symbol.iterator]() {
520
+ for (let element of this.toArray()) {
521
+ yield element;
522
+ }
523
+ }
519
524
  anyMatch(predicate) {
520
525
  if (isFunction(predicate)) {
521
526
  try {
522
- return useAnyMatch(predicate).collect(this);
527
+ return useSynchronousAnyMatch(predicate).collect(this.source());
523
528
  }
524
529
  catch (error) {
525
- throw new Error("Uncaught error on anyMatch.");
530
+ throw error;
526
531
  }
527
532
  }
528
533
  throw new TypeError("Predicate must be a function.");
529
534
  }
530
535
  allMatch(predicate) {
531
- return useAllMatch(predicate).collect(this);
536
+ return useSynchronousAllMatch(predicate).collect(this.source());
532
537
  }
533
538
  collect(argument1, argument2, argument3, argument4) {
534
539
  try {
535
- if (isCollector(argument1)) {
540
+ if (isSynchronousCollector(argument1)) {
536
541
  let collector = argument1;
537
- return collector.collect(this);
542
+ return collector.collect(this.source());
538
543
  }
539
544
  if (isFunction(argument1) && isFunction(argument2) && isFunction(argument3)) {
540
545
  let identity = argument1;
541
546
  let accumulator = argument2;
542
547
  let finisher = argument3;
543
- return useCollect(identity, accumulator, finisher).collect(this);
548
+ return useSynchronousCollect(identity, accumulator, finisher).collect(this.source());
544
549
  }
545
550
  if (isFunction(argument1) && isFunction(argument2) && isFunction(argument3) && isFunction(argument4)) {
546
551
  let identity = argument1;
547
552
  let interrupt = argument2;
548
553
  let accumulator = argument3;
549
554
  let finisher = argument4;
550
- return useCollect(identity, interrupt, accumulator, finisher).collect(this);
555
+ return useSynchronousCollect(identity, interrupt, accumulator, finisher).collect(this.source());
551
556
  }
552
557
  }
553
558
  catch (error) {
554
- throw new Error("Uncaught error on collect.");
559
+ throw error;
555
560
  }
556
561
  throw new TypeError("Invalid arguments.");
557
562
  }
558
563
  count() {
559
- return useCount().collect(this.source());
564
+ return useSynchronousCount().collect(this.source());
560
565
  }
561
566
  error(argument1, argument2, argument3) {
562
567
  if (invalidate(argument1) && invalidate(argument2) && invalidate(argument3)) {
563
568
  try {
564
- useError().collect(this.source());
569
+ useSynchronousError().collect(this.source());
565
570
  }
566
571
  catch (error) {
567
- throw new Error("Uncaught error on error.");
572
+ throw error;
568
573
  }
569
574
  }
570
575
  else if (isFunction(argument1) && invalidate(argument2) && invalidate(argument3)) {
571
576
  try {
572
577
  let accumulator = argument1;
573
- useError(accumulator).collect(this.source());
578
+ useSynchronousError(accumulator).collect(this.source());
574
579
  }
575
580
  catch (error) {
576
- throw new Error("Uncaught error on error.");
581
+ throw error;
577
582
  }
578
583
  }
579
584
  else if (isString(argument1) && isFunction(argument2) && isString(argument3)) {
@@ -581,10 +586,10 @@ export class Collectable {
581
586
  let prefix = argument1;
582
587
  let accumulator = argument2;
583
588
  let suffix = argument3;
584
- useError(prefix, accumulator, suffix).collect(this.source());
589
+ useSynchronousError(prefix, accumulator, suffix).collect(this.source());
585
590
  }
586
591
  catch (error) {
587
- throw new Error("Uncaught error on error.");
592
+ throw error;
588
593
  }
589
594
  }
590
595
  else {
@@ -596,72 +601,72 @@ export class Collectable {
596
601
  }
597
602
  findAny() {
598
603
  try {
599
- return useFindAny().collect(this.source());
604
+ return useSynchronousFindAny().collect(this.source());
600
605
  }
601
606
  catch (error) {
602
- throw new Error("Uncaught error on findAny.");
607
+ throw error;
603
608
  }
604
609
  }
605
610
  findAt(index) {
606
611
  if (isBigInt(index)) {
607
612
  try {
608
- return useFindAt(index).collect(this.source());
613
+ return useSynchronousFindAt(index).collect(this.source());
609
614
  }
610
615
  catch (error) {
611
- throw new Error("Uncaught error on findAt.");
616
+ throw error;
612
617
  }
613
618
  }
614
619
  else if (isNumber(index)) {
615
620
  try {
616
- return useFindAt(index).collect(this.source());
621
+ return useSynchronousFindAt(index).collect(this.source());
617
622
  }
618
623
  catch (error) {
619
- throw new Error("Uncaught error on findAt.");
624
+ throw error;
620
625
  }
621
626
  }
622
627
  throw new TypeError("Index must be a bigint.");
623
628
  }
624
629
  findFirst() {
625
630
  try {
626
- return useFindFirst().collect(this.source());
631
+ return useSynchronousFindFirst().collect(this.source());
627
632
  }
628
633
  catch (error) {
629
- throw new Error("Uncaught error on findFirst.");
634
+ throw error;
630
635
  }
631
636
  }
632
637
  findLast() {
633
638
  try {
634
- return useFindLast().collect(this.source());
639
+ return useSynchronousFindLast().collect(this.source());
635
640
  }
636
641
  catch (error) {
637
- throw new Error("Uncaught error on findLast.");
642
+ throw error;
638
643
  }
639
644
  }
640
645
  findMaximum(argument1) {
641
646
  try {
642
647
  let comparator = isFunction(argument1) ? argument1 : useCompare;
643
- return useFindMaximum(comparator).collect(this.source());
648
+ return useSynchronousFindMaximum(comparator).collect(this.source());
644
649
  }
645
650
  catch (error) {
646
- throw new Error("Uncaught error on findMaximum.");
651
+ throw error;
647
652
  }
648
653
  }
649
654
  findMinimum(argument1) {
650
655
  try {
651
656
  let comparator = isFunction(argument1) ? argument1 : useCompare;
652
- return useFindMinimum(comparator).collect(this.source());
657
+ return useSynchronousFindMinimum(comparator).collect(this.source());
653
658
  }
654
659
  catch (error) {
655
- throw new Error("Uncaught error on findMinimum.");
660
+ throw error;
656
661
  }
657
662
  }
658
663
  forEach(action) {
659
664
  if (isFunction(action)) {
660
665
  try {
661
- useForEach(action).collect(this);
666
+ useSynchronousForEach(action).collect(this.source());
662
667
  }
663
668
  catch (error) {
664
- throw new Error("Uncaught error on forEach.");
669
+ throw error;
665
670
  }
666
671
  }
667
672
  else {
@@ -671,10 +676,10 @@ export class Collectable {
671
676
  group(classifier) {
672
677
  if (isFunction(classifier)) {
673
678
  try {
674
- return useGroup(classifier).collect(this.source());
679
+ return useSynchronousGroup(classifier).collect(this.source());
675
680
  }
676
681
  catch (error) {
677
- throw new Error("Uncaught error on group.");
682
+ throw error;
678
683
  }
679
684
  }
680
685
  throw new TypeError("Classifier must be a function.");
@@ -682,10 +687,10 @@ export class Collectable {
682
687
  groupBy(keyExtractor, valueExtractor) {
683
688
  if (isFunction(keyExtractor) && isFunction(valueExtractor)) {
684
689
  try {
685
- return useGroupBy(keyExtractor, valueExtractor).collect(this.source());
690
+ return useSynchronousGroupBy(keyExtractor, valueExtractor).collect(this.source());
686
691
  }
687
692
  catch (error) {
688
- throw new Error("Uncaught error on groupBy.");
693
+ throw error;
689
694
  }
690
695
  }
691
696
  throw new TypeError("Key and value extractors must be functions.");
@@ -693,19 +698,19 @@ export class Collectable {
693
698
  join(argument1, argument2, argument3) {
694
699
  if (invalidate(argument1) && invalidate(argument2) && invalidate(argument3)) {
695
700
  try {
696
- return useJoin().collect(this.source());
701
+ return useSynchronousJoin().collect(this.source());
697
702
  }
698
703
  catch (error) {
699
- throw new Error("Uncaught error on join.");
704
+ throw error;
700
705
  }
701
706
  }
702
707
  else if (isString(argument1) && invalidate(argument2) && invalidate(argument3)) {
703
708
  try {
704
709
  let delimiter = argument1;
705
- return useJoin(delimiter).collect(this.source());
710
+ return useSynchronousJoin(delimiter).collect(this.source());
706
711
  }
707
712
  catch (error) {
708
- throw new Error("Uncaught error on join.");
713
+ throw error;
709
714
  }
710
715
  }
711
716
  else if (isString(argument1) && isFunction(argument2) && isString(argument3)) {
@@ -713,10 +718,10 @@ export class Collectable {
713
718
  let prefix = argument1;
714
719
  let accumulator = argument2;
715
720
  let suffix = argument3;
716
- return useJoin(prefix, accumulator, suffix).collect(this.source());
721
+ return useSynchronousJoin(prefix, accumulator, suffix).collect(this.source());
717
722
  }
718
723
  catch (error) {
719
- throw new Error("Uncaught error on join.");
724
+ throw error;
720
725
  }
721
726
  }
722
727
  else if (isString(argument1) && isString(argument2) && isString(argument3)) {
@@ -724,10 +729,10 @@ export class Collectable {
724
729
  let prefix = argument1;
725
730
  let delimiter = argument2;
726
731
  let suffix = argument3;
727
- return useJoin(prefix, delimiter, suffix).collect(this.source());
732
+ return useSynchronousJoin(prefix, delimiter, suffix).collect(this.source());
728
733
  }
729
734
  catch (error) {
730
- throw new Error("Uncaught error on join.");
735
+ throw error;
731
736
  }
732
737
  }
733
738
  throw new TypeError("Invalid arguments.");
@@ -736,10 +741,10 @@ export class Collectable {
736
741
  if (isFunction(argument1) && invalidate(argument2) && invalidate(argument3)) {
737
742
  try {
738
743
  let accumulator = argument1;
739
- useLog(accumulator).collect(this.source());
744
+ useSynchronousLog(accumulator).collect(this.source());
740
745
  }
741
746
  catch (error) {
742
- throw new Error("Uncaught error on log.");
747
+ throw error;
743
748
  }
744
749
  }
745
750
  else if (isString(argument1) && isFunction(argument2) && isString(argument3)) {
@@ -747,28 +752,28 @@ export class Collectable {
747
752
  let prefix = argument1;
748
753
  let accumulator = argument2;
749
754
  let suffix = argument3;
750
- useLog(prefix, accumulator, suffix).collect(this.source());
755
+ useSynchronousLog(prefix, accumulator, suffix).collect(this.source());
751
756
  }
752
757
  catch (error) {
753
- throw new Error("Uncaught error on log.");
758
+ throw error;
754
759
  }
755
760
  }
756
761
  else {
757
762
  try {
758
- useLog().collect(this.source());
763
+ useSynchronousLog().collect(this.source());
759
764
  }
760
765
  catch (error) {
761
- throw new Error("Uncaught error on log.");
766
+ throw error;
762
767
  }
763
768
  }
764
769
  }
765
770
  nonMatch(predicate) {
766
771
  if (isFunction(predicate)) {
767
772
  try {
768
- return useNoneMatch(predicate).collect(this.source());
773
+ return useSynchronousNoneMatch(predicate).collect(this.source());
769
774
  }
770
775
  catch (error) {
771
- throw new Error("Uncaught error on nonMatch.");
776
+ throw error;
772
777
  }
773
778
  }
774
779
  throw new TypeError("Predicate must be a function.");
@@ -776,10 +781,10 @@ export class Collectable {
776
781
  partition(count) {
777
782
  if (isBigInt(count)) {
778
783
  try {
779
- return usePartition(count).collect(this.source());
784
+ return useSynchronousPartition(count).collect(this.source());
780
785
  }
781
786
  catch (error) {
782
- throw new Error("Uncaught error on partition.");
787
+ throw error;
783
788
  }
784
789
  }
785
790
  throw new TypeError("Count must be a BigInt.");
@@ -787,11 +792,11 @@ export class Collectable {
787
792
  partitionBy(classifier) {
788
793
  if (isFunction(classifier)) {
789
794
  try {
790
- let collector = usePartitionBy(classifier);
795
+ let collector = useSynchronousPartitionBy(classifier);
791
796
  return collector.collect(this.source());
792
797
  }
793
798
  catch (error) {
794
- throw new Error("Uncaught error on partitionBy.");
799
+ throw error;
795
800
  }
796
801
  }
797
802
  throw new TypeError("Classifier must be a function.");
@@ -800,20 +805,20 @@ export class Collectable {
800
805
  if (isFunction(argument1) && invalidate(argument2) && invalidate(argument3)) {
801
806
  try {
802
807
  let accumulator = argument1;
803
- return useReduce(accumulator).collect(this.source());
808
+ return useSynchronousReduce(accumulator).collect(this.source());
804
809
  }
805
810
  catch (error) {
806
- throw new Error("Uncaught error on reduce.");
811
+ throw error;
807
812
  }
808
813
  }
809
814
  else if (validate(argument1) && isFunction(argument2) && invalidate(argument3)) {
810
815
  try {
811
816
  let identity = argument1;
812
817
  let accumulator = argument2;
813
- return useReduce(identity, accumulator).collect(this.source());
818
+ return useSynchronousReduce(identity, accumulator).collect(this.source());
814
819
  }
815
820
  catch (error) {
816
- throw new Error("Uncaught error on reduce.");
821
+ throw error;
817
822
  }
818
823
  }
819
824
  else if (validate(argument1) && isFunction(argument2) && isFunction(argument3)) {
@@ -821,10 +826,10 @@ export class Collectable {
821
826
  let identity = argument1;
822
827
  let accumulator = argument2;
823
828
  let finisher = argument3;
824
- return useReduce(identity, accumulator, finisher).collect(this.source());
829
+ return useSynchronousReduce(identity, accumulator, finisher).collect(this.source());
825
830
  }
826
831
  catch (error) {
827
- throw new Error("Uncaught error on reduce.");
832
+ throw error;
828
833
  }
829
834
  }
830
835
  else {
@@ -835,10 +840,10 @@ export class Collectable {
835
840
  let source = this.source();
836
841
  if (isFunction(source)) {
837
842
  try {
838
- return new Semantic(source);
843
+ return new SynchronousSemantic(source);
839
844
  }
840
845
  catch (error) {
841
- throw new Error("Uncaught error on semantic.");
846
+ throw error;
842
847
  }
843
848
  }
844
849
  else {
@@ -847,26 +852,26 @@ export class Collectable {
847
852
  }
848
853
  toArray() {
849
854
  try {
850
- return useToArray().collect(this.source());
855
+ return useSynchronousToArray().collect(this.source());
851
856
  }
852
857
  catch (error) {
853
- throw new Error("Uncaught error on toArray.");
858
+ throw error;
854
859
  }
855
860
  }
856
861
  toMap(keyExtractor, valueExtractor = (element) => element) {
857
862
  try {
858
- return useToMap(keyExtractor, valueExtractor).collect(this.source());
863
+ return useSynchronousToMap(keyExtractor, valueExtractor).collect(this.source());
859
864
  }
860
865
  catch (error) {
861
- throw new Error("Uncaught error on toMap.");
866
+ throw error;
862
867
  }
863
868
  }
864
869
  toSet() {
865
870
  try {
866
- return useToSet().collect(this.source());
871
+ return useSynchronousToSet().collect(this.source());
867
872
  }
868
873
  catch (error) {
869
- throw new Error("Uncaught error on toSet.");
874
+ throw error;
870
875
  }
871
876
  }
872
877
  write(argument1, argument2) {
@@ -875,146 +880,56 @@ export class Collectable {
875
880
  let stream = argument1;
876
881
  if (isFunction(argument2)) {
877
882
  let accumulator = argument2;
878
- return useWrite(stream, accumulator).collect(this.source());
883
+ return useSynchronousWrite(stream, accumulator).collect(this.source());
879
884
  }
880
885
  else {
881
- return useWrite(stream).collect(this.source());
886
+ return useSynchronousWrite(stream).collect(this.source());
882
887
  }
883
888
  }
884
889
  catch (error) {
885
- throw new Error("Uncaught error on write.");
890
+ throw error;
886
891
  }
887
892
  }
888
893
  throw new TypeError("Invalid arguments.");
889
894
  }
890
895
  }
891
896
  ;
892
- export class EventCollectable extends Collectable {
893
- AsyncCollectable = AsyncCollectableSymbol;
894
- generator;
895
- constructor(argument1) {
896
- super();
897
- if (isFunction(argument1)) {
898
- let generator = argument1;
899
- this.generator = generator;
900
- Object.defineProperty(this, "AsyncCollectable", {
901
- value: AsyncCollectableSymbol,
902
- writable: false,
903
- enumerable: false,
904
- configurable: false
905
- });
906
- }
907
- else {
908
- throw new TypeError("Source must be an iterable or a generator function.");
909
- }
910
- }
911
- source() {
912
- return this.generator;
913
- }
914
- *[Symbol.iterator]() {
915
- try {
916
- let collector = useToArray();
917
- yield* collector.collect(this.generator);
918
- }
919
- catch (error) {
920
- throw new Error("Uncaught error on Generator.");
921
- }
922
- }
923
- async *[Symbol.asyncIterator]() {
924
- try {
925
- let collector = useToArray();
926
- yield* collector.collect(this.generator);
927
- }
928
- catch (error) {
929
- throw new Error("Uncaught error on Generator.");
930
- }
931
- }
932
- }
933
- export class UnorderedCollectable extends Collectable {
934
- UnorderedCollectable = UnorderedCollectableSymbol;
935
- buffer = new Map();
936
- constructor(argument1) {
937
- super();
938
- if (isFunction(argument1)) {
939
- let generator = argument1;
940
- generator((element, index) => {
941
- this.buffer.set(index, element);
942
- }, () => false);
943
- Object.defineProperties(this, {
944
- "UnorderedCollectable": {
945
- value: UnorderedCollectableSymbol,
946
- writable: false,
947
- enumerable: false,
948
- configurable: false
949
- }
950
- });
951
- }
952
- else {
953
- throw new TypeError("Source must be an iterable or a generator function.");
954
- }
955
- }
956
- source() {
957
- return (accept, interrupt) => {
958
- for (let [index, element] of this.buffer) {
959
- if (interrupt(element, index)) {
960
- break;
961
- }
962
- accept(element, index);
963
- }
964
- };
965
- }
966
- *[Symbol.iterator]() {
967
- try {
968
- for (let [_index, element] of this.buffer) {
969
- yield element;
970
- }
971
- }
972
- catch (error) {
973
- throw new Error("Uncaught error on Generator.");
974
- }
975
- }
976
- async *[Symbol.asyncIterator]() {
977
- try {
978
- for (let [_index, element] of this.buffer) {
979
- yield element;
980
- }
981
- }
982
- catch (error) {
983
- throw new Error("Uncaught error on AsyncGenerator.");
984
- }
985
- }
986
- }
987
- ;
988
- export class OrderedCollectable extends Collectable {
989
- OrderedCollectable = OrderedCollectableSymbol;
990
- buffer;
897
+ export class SynchronousOrderedCollectable extends SynchronousCollectable {
898
+ OrderedCollectable = SynchronousOrderedCollectableSymbol;
899
+ buffer = [];
900
+ [Symbol.toStringTag] = "SynchronousOrderedCollectable";
991
901
  constructor(argument1, argument2) {
992
902
  super();
993
903
  if (isFunction(argument1)) {
994
904
  try {
995
905
  if (isFunction(argument2)) {
996
- let collector = useToArray();
997
- this.buffer = collector.collect(argument1).sort(argument2).map((element, index) => {
906
+ let collector = useSynchronousToArray();
907
+ let generator = argument1;
908
+ let comparator = argument2;
909
+ this.buffer = collector.collect(generator).sort(comparator).map((element, index) => {
998
910
  return {
999
911
  element: element,
1000
912
  index: BigInt(index)
1001
913
  };
1002
914
  });
915
+ Object.freeze(this.buffer);
1003
916
  }
1004
917
  else {
1005
- let collector = useToArray();
1006
- this.buffer = collector.collect(argument1).map((element, index) => {
918
+ let collector = useSynchronousToArray();
919
+ let generator = argument1;
920
+ this.buffer = collector.collect(generator).map((element, index, array) => {
1007
921
  return {
1008
922
  element: element,
1009
- index: BigInt(index)
923
+ index: BigInt(((index % array.length) + array.length) % array.length)
1010
924
  };
1011
925
  }).sort((a, b) => {
1012
926
  return Number(a.index - b.index);
1013
927
  });
928
+ Object.freeze(this.buffer);
1014
929
  }
1015
930
  Object.defineProperties(this, {
1016
- "OrderedCollectable": {
1017
- value: OrderedCollectableSymbol,
931
+ "SynchronousOrderedCollectable": {
932
+ value: SynchronousOrderedCollectableSymbol,
1018
933
  writable: false,
1019
934
  enumerable: false,
1020
935
  configurable: false
@@ -1036,52 +951,82 @@ export class OrderedCollectable extends Collectable {
1036
951
  }
1037
952
  }
1038
953
  *[Symbol.iterator]() {
1039
- try {
1040
- for (let indexed of this.buffer) {
1041
- yield indexed.element;
1042
- }
1043
- }
1044
- catch (error) {
1045
- throw new Error("Uncaught error on Generator.");
954
+ for (let { element } of this.buffer) {
955
+ yield element;
1046
956
  }
1047
957
  }
1048
- async *[Symbol.asyncIterator]() {
1049
- try {
1050
- for (let indexed of this.buffer) {
1051
- yield indexed.element;
1052
- }
1053
- }
1054
- catch (error) {
1055
- throw new Error("Uncaught error on AsyncGenerator.");
1056
- }
958
+ allMatch(predicate) {
959
+ let collector = SynchronousCollector.shortable(() => false, (element, index, accumulator) => predicate(element.element, index) && accumulator, (accumulator, element, index) => predicate(element.element, index) && accumulator, (result) => result);
960
+ return collector.collect(this.buffer);
1057
961
  }
1058
962
  source() {
1059
- try {
1060
- return (accept, interrupt) => {
1061
- for (let indexed of this.buffer) {
1062
- if (interrupt(indexed.element, indexed.index)) {
1063
- break;
1064
- }
1065
- accept(indexed.element, indexed.index);
963
+ return (accept, interrupt) => {
964
+ for (let { element, index } of this.buffer) {
965
+ if (interrupt(element, index)) {
966
+ break;
1066
967
  }
1067
- };
1068
- }
1069
- catch (error) {
1070
- throw new Error("Uncaught error on creating source.");
1071
- }
968
+ accept(element, index);
969
+ }
970
+ };
1072
971
  }
1073
972
  isEmpty() {
1074
973
  return this.buffer.length === 0;
1075
974
  }
975
+ count() {
976
+ return BigInt(this.buffer.length);
977
+ }
1076
978
  }
1077
979
  ;
1078
- export class Statistics extends OrderedCollectable {
1079
- Statistics = StatisticsSymbol;
980
+ export class SynchronousUnorderedCollectable extends SynchronousCollectable {
981
+ SynchronousUnorderedCollectable = SynchronousUnorderedCollectableSymbol;
982
+ [Symbol.toStringTag] = "SynchronousUnorderedCollectable";
983
+ buffer = new Map();
984
+ constructor(argument1) {
985
+ super();
986
+ if (isFunction(argument1)) {
987
+ let generator = argument1;
988
+ generator((element, index) => {
989
+ this.buffer.set(index, element);
990
+ }, () => false);
991
+ Object.freeze(this.buffer);
992
+ Object.defineProperties(this, {
993
+ "SynchronousUnorderedCollectable": {
994
+ value: SynchronousUnorderedCollectableSymbol,
995
+ writable: false,
996
+ enumerable: false,
997
+ configurable: false
998
+ }
999
+ });
1000
+ }
1001
+ else {
1002
+ throw new TypeError("Source must be an iterable or a generator function.");
1003
+ }
1004
+ }
1005
+ *[Symbol.iterator]() {
1006
+ for (let [_index, element] of this.buffer) {
1007
+ yield element;
1008
+ }
1009
+ }
1010
+ source() {
1011
+ return (accept, interrupt) => {
1012
+ for (let [_index, element] of this.buffer) {
1013
+ if (interrupt(element, _index)) {
1014
+ break;
1015
+ }
1016
+ accept(element, _index);
1017
+ }
1018
+ };
1019
+ }
1020
+ }
1021
+ ;
1022
+ export class SynchronousStatistics extends SynchronousOrderedCollectable {
1023
+ SynchronousStatistics = SynchronousStatisticsSymbol;
1024
+ [Symbol.toStringTag] = "SynchronousStatistics";
1080
1025
  constructor(parameter, comparator) {
1081
- super(parameter, comparator || useCompare);
1026
+ super(parameter, validate(comparator) ? comparator : useCompare);
1082
1027
  Object.defineProperties(this, {
1083
- "Statistics": {
1084
- value: StatisticsSymbol,
1028
+ "SynchronousStatistics": {
1029
+ value: SynchronousStatisticsSymbol,
1085
1030
  enumerable: false,
1086
1031
  writable: false,
1087
1032
  configurable: false
@@ -1089,40 +1034,23 @@ export class Statistics extends OrderedCollectable {
1089
1034
  });
1090
1035
  }
1091
1036
  *[Symbol.iterator]() {
1092
- try {
1093
- for (let indexed of this.buffer) {
1094
- yield indexed.element;
1095
- }
1096
- }
1097
- catch (error) {
1098
- throw new Error("Uncaught error on Generator.");
1037
+ for (let { element } of this.buffer) {
1038
+ yield element;
1099
1039
  }
1100
1040
  }
1101
- async *[Symbol.asyncIterator]() {
1102
- try {
1103
- for (let indexed of this.buffer) {
1104
- yield indexed.element;
1105
- }
1106
- }
1107
- catch (error) {
1108
- throw new Error("Uncaught error on AsyncGenerator.");
1109
- }
1110
- }
1111
- count() {
1112
- return BigInt(this.buffer.length);
1113
- }
1114
1041
  frequency() {
1115
- return useFrequency().collect(this.source());
1042
+ return useSynchronousFrequency().collect(this.source());
1116
1043
  }
1117
1044
  }
1118
1045
  ;
1119
- export class NumericStatistics extends Statistics {
1120
- NumericStatistics = NumericStatisticsSymbol;
1046
+ export class SynchronousBigIntStatistics extends SynchronousStatistics {
1047
+ BigIntStatistics = SynchronousBigIntStatisticsSymbol;
1048
+ [Symbol.toStringTag] = "SynchronousBigIntStatistics";
1121
1049
  constructor(parameter, comparator) {
1122
1050
  super(parameter, comparator || useCompare);
1123
1051
  Object.defineProperties(this, {
1124
- "NumericStatistics": {
1125
- value: NumericStatisticsSymbol,
1052
+ "SynchronousBigIntStatistics": {
1053
+ value: SynchronousBigIntStatisticsSymbol,
1126
1054
  enumerable: false,
1127
1055
  writable: false,
1128
1056
  configurable: false
@@ -1130,34 +1058,17 @@ export class NumericStatistics extends Statistics {
1130
1058
  });
1131
1059
  }
1132
1060
  *[Symbol.iterator]() {
1133
- try {
1134
- for (let indexed of this.buffer) {
1135
- yield indexed.element;
1136
- }
1137
- }
1138
- catch (error) {
1139
- throw new Error("Uncaught error on Generator.");
1061
+ for (let { element } of this.buffer) {
1062
+ yield element;
1140
1063
  }
1141
1064
  }
1142
- async *[Symbol.asyncIterator]() {
1143
- try {
1144
- for (let indexed of this.buffer) {
1145
- yield indexed.element;
1146
- }
1147
- }
1148
- catch (error) {
1149
- throw new Error("Uncaught error on AsyncGenerator.");
1150
- }
1151
- }
1152
- average(mapper) {
1065
+ average(argument1) {
1153
1066
  if (this.isEmpty()) {
1154
- return 0;
1067
+ return 0n;
1155
1068
  }
1156
1069
  try {
1157
- if (isFunction(mapper)) {
1158
- return useNumericAverage(mapper).collect(this.source());
1159
- }
1160
- return useNumericAverage().collect(this.source());
1070
+ let mapper = isFunction(argument1) ? argument1 : useToBigInt;
1071
+ return useSynchronousBigIntAverage(mapper).collect(this.source());
1161
1072
  }
1162
1073
  catch (error) {
1163
1074
  throw new Error("Uncaught error on average.");
@@ -1165,17 +1076,18 @@ export class NumericStatistics extends Statistics {
1165
1076
  }
1166
1077
  range(argument1) {
1167
1078
  if (this.isEmpty()) {
1168
- return 0;
1079
+ return 0n;
1169
1080
  }
1170
1081
  try {
1171
- if (this.count() === 1n) {
1172
- return 0;
1173
- }
1174
- let mapper = isFunction(argument1) ? argument1 : useToNumber;
1175
- let count = this.buffer.length;
1176
- let minimum = this.buffer[0].element;
1177
- let maximum = this.buffer[count - 1].element;
1178
- return mapper(maximum) - mapper(minimum);
1082
+ let mapper = isFunction(argument1) ? argument1 : useToBigInt;
1083
+ let minimum = this.findFirst();
1084
+ let maximum = this.findLast();
1085
+ return minimum.flatMap((minimum) => {
1086
+ return maximum.map((maximum) => {
1087
+ let difference = mapper(maximum) - mapper(minimum);
1088
+ return difference < 0n ? -difference : difference;
1089
+ });
1090
+ }).get(0n);
1179
1091
  }
1180
1092
  catch (error) {
1181
1093
  throw new Error("Uncaught error on range.");
@@ -1183,11 +1095,11 @@ export class NumericStatistics extends Statistics {
1183
1095
  }
1184
1096
  variance(argument1) {
1185
1097
  if (this.isEmpty() || this.count() === 1n) {
1186
- return 0;
1098
+ return 0n;
1187
1099
  }
1188
1100
  try {
1189
- let mapper = isFunction(argument1) ? argument1 : useToNumber;
1190
- return useNumericVariance(mapper).collect(this.source());
1101
+ let mapper = isFunction(argument1) ? argument1 : useToBigInt;
1102
+ return useSynchronousBigIntVariance(mapper).collect(this.source());
1191
1103
  }
1192
1104
  catch (error) {
1193
1105
  throw new Error("Uncaught error on variance.");
@@ -1195,8 +1107,9 @@ export class NumericStatistics extends Statistics {
1195
1107
  }
1196
1108
  standardDeviation(argument1) {
1197
1109
  try {
1198
- let mapper = isFunction(argument1) ? argument1 : useToNumber;
1199
- return useNumericStandardDeviation(mapper).collect(this.source());
1110
+ let mapper = isFunction(argument1) ? argument1 : useToBigInt;
1111
+ let variance = this.variance(mapper);
1112
+ return BigInt(Math.sqrt(Number(variance)));
1200
1113
  }
1201
1114
  catch (error) {
1202
1115
  throw new Error("Uncaught error on standardDeviation.");
@@ -1204,11 +1117,11 @@ export class NumericStatistics extends Statistics {
1204
1117
  }
1205
1118
  mean(argument1) {
1206
1119
  if (this.isEmpty()) {
1207
- return 0;
1120
+ return 0n;
1208
1121
  }
1209
1122
  try {
1210
- let mapper = isFunction(argument1) ? argument1 : useToNumber;
1211
- return useNumericAverage(mapper).collect(this.source());
1123
+ let mapper = isFunction(argument1) ? argument1 : useToBigInt;
1124
+ return useSynchronousBigIntAverage(mapper).collect(this.source());
1212
1125
  }
1213
1126
  catch (error) {
1214
1127
  throw new Error("Uncaught error on mean.");
@@ -1216,11 +1129,11 @@ export class NumericStatistics extends Statistics {
1216
1129
  }
1217
1130
  median(argument1) {
1218
1131
  if (this.isEmpty()) {
1219
- return 0;
1132
+ return 0n;
1220
1133
  }
1221
1134
  try {
1222
- let mapper = isFunction(argument1) ? argument1 : useToNumber;
1223
- return useNumericMedian(mapper).collect(this.source());
1135
+ let mapper = isFunction(argument1) ? argument1 : useToBigInt;
1136
+ return useSynchronousBigIntMedian(mapper).collect(this.source());
1224
1137
  }
1225
1138
  catch (error) {
1226
1139
  throw new Error("Uncaught error on median.");
@@ -1228,11 +1141,11 @@ export class NumericStatistics extends Statistics {
1228
1141
  }
1229
1142
  mode(argument1) {
1230
1143
  if (this.isEmpty()) {
1231
- return 0;
1144
+ return 0n;
1232
1145
  }
1233
1146
  try {
1234
- let mapper = isFunction(argument1) ? argument1 : useToNumber;
1235
- return useNumericMode(mapper).collect(this.source());
1147
+ let mapper = isFunction(argument1) ? argument1 : useToBigInt;
1148
+ return useSynchronousBigIntMode(mapper).collect(this.source());
1236
1149
  }
1237
1150
  catch (error) {
1238
1151
  throw new Error("Uncaught error on mode.");
@@ -1240,11 +1153,11 @@ export class NumericStatistics extends Statistics {
1240
1153
  }
1241
1154
  summate(argument1) {
1242
1155
  if (this.isEmpty()) {
1243
- return 0;
1156
+ return 0n;
1244
1157
  }
1245
1158
  try {
1246
- let mapper = isFunction(argument1) ? argument1 : useToNumber;
1247
- return useNumericSummate(mapper).collect(this.source());
1159
+ let mapper = isFunction(argument1) ? argument1 : useToBigInt;
1160
+ return useSynchronousBigIntSummate(mapper).collect(this.source());
1248
1161
  }
1249
1162
  catch (error) {
1250
1163
  throw new Error("Uncaught error on summate.");
@@ -1252,20 +1165,19 @@ export class NumericStatistics extends Statistics {
1252
1165
  }
1253
1166
  quantile(quantile, argument1) {
1254
1167
  if (this.isEmpty()) {
1255
- return 0;
1168
+ return 0n;
1256
1169
  }
1257
- if (quantile < 0 || quantile > 1) {
1170
+ if (!isNumber(quantile) || quantile < 0 || quantile > 1) {
1258
1171
  throw new RangeError("Invalid quantile.");
1259
1172
  }
1260
1173
  try {
1261
- let mapper = isFunction(argument1) ? argument1 : useToNumber;
1174
+ let mapper = isFunction(argument1) ? argument1 : useToBigInt;
1262
1175
  let count = Number(this.count());
1263
1176
  let index = Math.floor(quantile * count);
1264
1177
  if (index === count) {
1265
1178
  index--;
1266
1179
  }
1267
- let value = mapper(this.buffer[index].element);
1268
- return value;
1180
+ return this.findAt(index).map(mapper).get(0n);
1269
1181
  }
1270
1182
  catch (error) {
1271
1183
  throw new Error("Uncaught error on quantile.");
@@ -1273,10 +1185,10 @@ export class NumericStatistics extends Statistics {
1273
1185
  }
1274
1186
  interquartileRange(argument1) {
1275
1187
  if (this.isEmpty()) {
1276
- return 0;
1188
+ return 0n;
1277
1189
  }
1278
1190
  try {
1279
- let mapper = isFunction(argument1) ? argument1 : useToNumber;
1191
+ let mapper = isFunction(argument1) ? argument1 : useToBigInt;
1280
1192
  let lower = this.quantile(0.25, mapper);
1281
1193
  let upper = this.quantile(0.75, mapper);
1282
1194
  return upper - lower;
@@ -1287,22 +1199,22 @@ export class NumericStatistics extends Statistics {
1287
1199
  }
1288
1200
  skewness(argument1) {
1289
1201
  if (this.isEmpty()) {
1290
- return 0;
1202
+ return 0n;
1291
1203
  }
1292
1204
  try {
1293
- let mapper = isFunction(argument1) ? argument1 : useToNumber;
1205
+ let mapper = isFunction(argument1) ? argument1 : useToBigInt;
1294
1206
  let mean = this.mean(mapper);
1295
1207
  let standardDeviation = this.standardDeviation(mapper);
1296
- if (standardDeviation === 0) {
1297
- return 0;
1208
+ if (standardDeviation === 0n) {
1209
+ return 0n;
1298
1210
  }
1299
- let data = this.toArray().map(item => mapper(item));
1300
- let summate = 0;
1211
+ let data = (this.toArray()).map((element) => mapper(element));
1212
+ let summate = 0n;
1301
1213
  for (let value of data) {
1302
- let z = (value - mean) / standardDeviation;
1303
- summate += Math.pow(z, 3);
1214
+ let z = value - mean;
1215
+ summate += z * z * z;
1304
1216
  }
1305
- return summate / data.length;
1217
+ return summate / BigInt(data.length);
1306
1218
  }
1307
1219
  catch (error) {
1308
1220
  throw new Error("Uncaught error on skewness.");
@@ -1310,22 +1222,23 @@ export class NumericStatistics extends Statistics {
1310
1222
  }
1311
1223
  kurtosis(argument1) {
1312
1224
  if (this.isEmpty()) {
1313
- return 0;
1225
+ return 0n;
1314
1226
  }
1315
1227
  try {
1316
- let mapper = isFunction(argument1) ? argument1 : useToNumber;
1228
+ let mapper = isFunction(argument1) ? argument1 : useToBigInt;
1317
1229
  let mean = this.mean(mapper);
1318
1230
  let standardDeviation = this.standardDeviation(mapper);
1319
- if (standardDeviation === 0) {
1320
- return 0;
1231
+ if (standardDeviation === 0n) {
1232
+ return 0n;
1321
1233
  }
1322
- let data = this.toArray().map(item => mapper(item));
1323
- let summate = 0;
1234
+ let data = (this.toArray()).map((element) => mapper(element));
1235
+ let summate = 0n;
1236
+ let count = data.length;
1324
1237
  for (let value of data) {
1325
- let z = (value - mean) / standardDeviation;
1326
- summate += Math.pow(z, 4);
1238
+ let z = value - mean;
1239
+ summate += z * z * z * z;
1327
1240
  }
1328
- return summate / (data.length * data.length) - 3;
1241
+ return summate / BigInt(count * count) - 3n;
1329
1242
  }
1330
1243
  catch (error) {
1331
1244
  throw new Error("Uncaught error on kurtosis.");
@@ -1333,13 +1246,14 @@ export class NumericStatistics extends Statistics {
1333
1246
  }
1334
1247
  }
1335
1248
  ;
1336
- export class BigIntStatistics extends Statistics {
1337
- BigIntStatistics = BigIntStatisticsSymbol;
1249
+ export class SynchronousNumericStatistics extends SynchronousStatistics {
1250
+ SynchronousNumericStatistics = SynchronousNumericStatisticsSymbol;
1251
+ [Symbol.toStringTag] = "SynchronousNumericStatistics";
1338
1252
  constructor(parameter, comparator) {
1339
1253
  super(parameter, comparator || useCompare);
1340
1254
  Object.defineProperties(this, {
1341
- "BigIntStatistics": {
1342
- value: BigIntStatisticsSymbol,
1255
+ "SynchronousNumericStatistics": {
1256
+ value: SynchronousNumericStatisticsSymbol,
1343
1257
  enumerable: false,
1344
1258
  writable: false,
1345
1259
  configurable: false
@@ -1347,32 +1261,19 @@ export class BigIntStatistics extends Statistics {
1347
1261
  });
1348
1262
  }
1349
1263
  *[Symbol.iterator]() {
1350
- try {
1351
- for (let indexed of this.buffer) {
1352
- yield indexed.element;
1353
- }
1354
- }
1355
- catch (error) {
1356
- throw new Error("Uncaught error on Generator.");
1264
+ for (let { element } of this.buffer) {
1265
+ yield element;
1357
1266
  }
1358
1267
  }
1359
- async *[Symbol.asyncIterator]() {
1360
- try {
1361
- for (let indexed of this.buffer) {
1362
- yield indexed.element;
1363
- }
1364
- }
1365
- catch (error) {
1366
- throw new Error("Uncaught error on AsyncGenerator.");
1367
- }
1368
- }
1369
- average(argument1) {
1268
+ average(mapper) {
1370
1269
  if (this.isEmpty()) {
1371
- return 0n;
1270
+ return 0;
1372
1271
  }
1373
1272
  try {
1374
- let mapper = isFunction(argument1) ? argument1 : useToBigInt;
1375
- return useBigIntAverage(mapper).collect(this.source());
1273
+ if (isFunction(mapper)) {
1274
+ return useSynchronousNumericAverage(mapper).collect(this.source());
1275
+ }
1276
+ return useSynchronousNumericAverage().collect(this.source());
1376
1277
  }
1377
1278
  catch (error) {
1378
1279
  throw new Error("Uncaught error on average.");
@@ -1380,14 +1281,21 @@ export class BigIntStatistics extends Statistics {
1380
1281
  }
1381
1282
  range(argument1) {
1382
1283
  if (this.isEmpty()) {
1383
- return 0n;
1284
+ return 0;
1384
1285
  }
1385
1286
  try {
1386
- let mapper = isFunction(argument1) ? argument1 : useToBigInt;
1387
- let count = this.buffer.length;
1388
- let minimum = this.buffer[0].element;
1389
- let maximum = this.buffer[count - 1].element;
1390
- return mapper(maximum) - mapper(minimum);
1287
+ if (this.count() === 1n) {
1288
+ return 0;
1289
+ }
1290
+ let mapper = isFunction(argument1) ? argument1 : useToNumber;
1291
+ let minimum = this.findFirst();
1292
+ let maximum = this.findLast();
1293
+ return minimum.flatMap((minimum) => {
1294
+ return maximum.map((maximum) => {
1295
+ let difference = mapper(maximum) - mapper(minimum);
1296
+ return difference < 0 ? -difference : difference;
1297
+ });
1298
+ }).get(0);
1391
1299
  }
1392
1300
  catch (error) {
1393
1301
  throw new Error("Uncaught error on range.");
@@ -1395,11 +1303,11 @@ export class BigIntStatistics extends Statistics {
1395
1303
  }
1396
1304
  variance(argument1) {
1397
1305
  if (this.isEmpty() || this.count() === 1n) {
1398
- return 0n;
1306
+ return 0;
1399
1307
  }
1400
1308
  try {
1401
- let mapper = isFunction(argument1) ? argument1 : useToBigInt;
1402
- return useBigIntVariance(mapper).collect(this.source());
1309
+ let mapper = isFunction(argument1) ? argument1 : useToNumber;
1310
+ return useSynchronousNumericVariance(mapper).collect(this.source());
1403
1311
  }
1404
1312
  catch (error) {
1405
1313
  throw new Error("Uncaught error on variance.");
@@ -1407,9 +1315,8 @@ export class BigIntStatistics extends Statistics {
1407
1315
  }
1408
1316
  standardDeviation(argument1) {
1409
1317
  try {
1410
- let mapper = isFunction(argument1) ? argument1 : useToBigInt;
1411
- let variance = this.variance(mapper);
1412
- return BigInt(Math.sqrt(Number(variance)));
1318
+ let mapper = isFunction(argument1) ? argument1 : useToNumber;
1319
+ return useSynchronousNumericStandardDeviation(mapper).collect(this.source());
1413
1320
  }
1414
1321
  catch (error) {
1415
1322
  throw new Error("Uncaught error on standardDeviation.");
@@ -1417,11 +1324,11 @@ export class BigIntStatistics extends Statistics {
1417
1324
  }
1418
1325
  mean(argument1) {
1419
1326
  if (this.isEmpty()) {
1420
- return 0n;
1327
+ return 0;
1421
1328
  }
1422
1329
  try {
1423
- let mapper = isFunction(argument1) ? argument1 : useToBigInt;
1424
- return useBigIntAverage(mapper).collect(this.source());
1330
+ let mapper = isFunction(argument1) ? argument1 : useToNumber;
1331
+ return useSynchronousNumericAverage(mapper).collect(this.source());
1425
1332
  }
1426
1333
  catch (error) {
1427
1334
  throw new Error("Uncaught error on mean.");
@@ -1429,11 +1336,11 @@ export class BigIntStatistics extends Statistics {
1429
1336
  }
1430
1337
  median(argument1) {
1431
1338
  if (this.isEmpty()) {
1432
- return 0n;
1339
+ return 0;
1433
1340
  }
1434
1341
  try {
1435
- let mapper = isFunction(argument1) ? argument1 : useToBigInt;
1436
- return useBigIntMedian(mapper).collect(this.source());
1342
+ let mapper = isFunction(argument1) ? argument1 : useToNumber;
1343
+ return useSynchronousNumericMedian(mapper).collect(this.source());
1437
1344
  }
1438
1345
  catch (error) {
1439
1346
  throw new Error("Uncaught error on median.");
@@ -1441,11 +1348,11 @@ export class BigIntStatistics extends Statistics {
1441
1348
  }
1442
1349
  mode(argument1) {
1443
1350
  if (this.isEmpty()) {
1444
- return 0n;
1351
+ return 0;
1445
1352
  }
1446
1353
  try {
1447
- let mapper = isFunction(argument1) ? argument1 : useToBigInt;
1448
- return useBigIntMode(mapper).collect(this.source());
1354
+ let mapper = isFunction(argument1) ? argument1 : useToNumber;
1355
+ return useSynchronousNumericMode(mapper).collect(this.source());
1449
1356
  }
1450
1357
  catch (error) {
1451
1358
  throw new Error("Uncaught error on mode.");
@@ -1453,11 +1360,11 @@ export class BigIntStatistics extends Statistics {
1453
1360
  }
1454
1361
  summate(argument1) {
1455
1362
  if (this.isEmpty()) {
1456
- return 0n;
1363
+ return 0;
1457
1364
  }
1458
1365
  try {
1459
- let mapper = isFunction(argument1) ? argument1 : useToBigInt;
1460
- return useBigIntSummate(mapper).collect(this.source());
1366
+ let mapper = isFunction(argument1) ? argument1 : useToNumber;
1367
+ return useSynchronousNumericSummate(mapper).collect(this.source());
1461
1368
  }
1462
1369
  catch (error) {
1463
1370
  throw new Error("Uncaught error on summate.");
@@ -1465,20 +1372,19 @@ export class BigIntStatistics extends Statistics {
1465
1372
  }
1466
1373
  quantile(quantile, argument1) {
1467
1374
  if (this.isEmpty()) {
1468
- return 0n;
1375
+ return 0;
1469
1376
  }
1470
- if (typeof quantile !== "number" || quantile < 0 || quantile > 1) {
1377
+ if (quantile < 0 || quantile > 1) {
1471
1378
  throw new RangeError("Invalid quantile.");
1472
1379
  }
1473
1380
  try {
1474
- let mapper = isFunction(argument1) ? argument1 : useToBigInt;
1381
+ let mapper = isFunction(argument1) ? argument1 : useToNumber;
1475
1382
  let count = Number(this.count());
1476
1383
  let index = Math.floor(quantile * count);
1477
1384
  if (index === count) {
1478
1385
  index--;
1479
1386
  }
1480
- let value = mapper(this.buffer[index].element);
1481
- return value;
1387
+ return this.findAt(index).map(mapper).get(0);
1482
1388
  }
1483
1389
  catch (error) {
1484
1390
  throw new Error("Uncaught error on quantile.");
@@ -1486,10 +1392,10 @@ export class BigIntStatistics extends Statistics {
1486
1392
  }
1487
1393
  interquartileRange(argument1) {
1488
1394
  if (this.isEmpty()) {
1489
- return 0n;
1395
+ return 0;
1490
1396
  }
1491
1397
  try {
1492
- let mapper = isFunction(argument1) ? argument1 : useToBigInt;
1398
+ let mapper = isFunction(argument1) ? argument1 : useToNumber;
1493
1399
  let lower = this.quantile(0.25, mapper);
1494
1400
  let upper = this.quantile(0.75, mapper);
1495
1401
  return upper - lower;
@@ -1500,22 +1406,22 @@ export class BigIntStatistics extends Statistics {
1500
1406
  }
1501
1407
  skewness(argument1) {
1502
1408
  if (this.isEmpty()) {
1503
- return 0n;
1409
+ return 0;
1504
1410
  }
1505
1411
  try {
1506
- let mapper = isFunction(argument1) ? argument1 : useToBigInt;
1412
+ let mapper = isFunction(argument1) ? argument1 : useToNumber;
1507
1413
  let mean = this.mean(mapper);
1508
1414
  let standardDeviation = this.standardDeviation(mapper);
1509
- if (standardDeviation === 0n) {
1510
- return 0n;
1415
+ if (standardDeviation === 0) {
1416
+ return 0;
1511
1417
  }
1512
- let data = this.toArray().map(item => mapper(item));
1513
- let summate = 0n;
1418
+ let data = (this.toArray()).map((element) => mapper(element));
1419
+ let summate = 0;
1514
1420
  for (let value of data) {
1515
- let z = value - mean;
1516
- summate += z * z * z;
1421
+ let z = (value - mean) / standardDeviation;
1422
+ summate += Math.pow(z, 3);
1517
1423
  }
1518
- return summate / BigInt(data.length);
1424
+ return summate / data.length;
1519
1425
  }
1520
1426
  catch (error) {
1521
1427
  throw new Error("Uncaught error on skewness.");
@@ -1523,23 +1429,22 @@ export class BigIntStatistics extends Statistics {
1523
1429
  }
1524
1430
  kurtosis(argument1) {
1525
1431
  if (this.isEmpty()) {
1526
- return 0n;
1432
+ return 0;
1527
1433
  }
1528
1434
  try {
1529
- let mapper = isFunction(argument1) ? argument1 : useToBigInt;
1435
+ let mapper = isFunction(argument1) ? argument1 : useToNumber;
1530
1436
  let mean = this.mean(mapper);
1531
1437
  let standardDeviation = this.standardDeviation(mapper);
1532
- if (standardDeviation === 0n) {
1533
- return 0n;
1438
+ if (standardDeviation === 0) {
1439
+ return 0;
1534
1440
  }
1535
- let data = this.toArray().map(item => mapper(item));
1536
- let summate = 0n;
1537
- let count = data.length;
1441
+ let data = (this.toArray()).map((element) => mapper(element));
1442
+ let summate = 0;
1538
1443
  for (let value of data) {
1539
- let z = value - mean;
1540
- summate += z * z * z * z;
1444
+ let z = (value - mean) / standardDeviation;
1445
+ summate += Math.pow(z, 4);
1541
1446
  }
1542
- return summate / BigInt(count * count) - 3n;
1447
+ return summate / (data.length * data.length) - 3;
1543
1448
  }
1544
1449
  catch (error) {
1545
1450
  throw new Error("Uncaught error on kurtosis.");
@@ -1547,13 +1452,14 @@ export class BigIntStatistics extends Statistics {
1547
1452
  }
1548
1453
  }
1549
1454
  ;
1550
- export class WindowCollectable extends OrderedCollectable {
1551
- WindowCollectable = WindowCollectableSymbol;
1455
+ export class SynchronousWindowCollectable extends SynchronousOrderedCollectable {
1456
+ WindowCollectable = SynchronousWindowCollectableSymbol;
1457
+ [Symbol.toStringTag] = "SynchronousWindowCollectable";
1552
1458
  constructor(parameter, comparator = useCompare) {
1553
1459
  super(parameter, comparator);
1554
1460
  Object.defineProperties(this, {
1555
- "WindowCollectable": {
1556
- value: WindowCollectableSymbol,
1461
+ "SynchronousWindowCollectable": {
1462
+ value: SynchronousWindowCollectableSymbol,
1557
1463
  writable: false,
1558
1464
  enumerable: false,
1559
1465
  configurable: false
@@ -1561,33 +1467,18 @@ export class WindowCollectable extends OrderedCollectable {
1561
1467
  });
1562
1468
  }
1563
1469
  *[Symbol.iterator]() {
1564
- try {
1565
- for (let indexed of this.buffer) {
1566
- yield indexed.element;
1567
- }
1568
- }
1569
- catch (error) {
1570
- throw new Error("Uncaught error on Generator.");
1571
- }
1572
- }
1573
- async *[Symbol.asyncIterator]() {
1574
- try {
1575
- for (let indexed of this.buffer) {
1576
- yield indexed.element;
1577
- }
1578
- }
1579
- catch (error) {
1580
- throw new Error("Uncaught error on AsyncGenerator.");
1470
+ for (let { element } of this.buffer) {
1471
+ yield element;
1581
1472
  }
1582
1473
  }
1583
1474
  slide(size, step = 1n) {
1584
1475
  if (size > 0n && step > 0n) {
1585
- return new Semantic((accepet, interrupt) => {
1476
+ return new SynchronousSemantic((accepet, interrupt) => {
1586
1477
  try {
1587
1478
  let index = 0n;
1588
1479
  for (let start = 0n; start < BigInt(this.buffer.length); start += step) {
1589
1480
  let end = start + size;
1590
- let inner = new Semantic((accept, interrupt) => {
1481
+ let inner = new SynchronousSemantic((accept, interrupt) => {
1591
1482
  for (let index = start; index < end && index < BigInt(this.buffer.length); index++) {
1592
1483
  let indexed = this.buffer[Number(index)];
1593
1484
  if (invalidate(indexed)) {