semantic-typescript 0.6.0 → 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,12 +1,14 @@
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, SynchronousCollector } from "./collector";
2
- import { isFunction, isSynchronousSemantic, isIterable, isNumber, isBigInt, isObject, isString, isSynchronousCollectable, isAsynchronousCollector } from "../guard";
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
3
  import { useHash } from "../hash";
4
4
  import { useCompare, useToBigInt, useToNumber } from "../hook";
5
- import { SynchronousBigIntStatisticsSymbol, SynchronousCollectableSymbol, SynchronousNumericStatisticsSymbol, SynchronousOrderedCollectableSymbol, SynchronousSemanticSymbol, SynchronousStatisticsSymbol, SynchronousUnorderedCollectableSymbol, SynchronousWindowCollectableSymbol } from "../symbol";
6
- import { invalidate, validate, } from "../utility";
5
+ import { SynchronousOrderedCollectableSymbol, SynchronousBigIntStatisticsSymbol, SynchronousCollectableSymbol, SynchronousNumericStatisticsSymbol, SynchronousSemanticSymbol, SynchronousWindowCollectableSymbol, SynchronousUnorderedCollectableSymbol, SynchronousStatisticsSymbol } from "../symbol";
6
+ import { invalidate, validate } from "../utility";
7
+ import { SynchronousCollector } from "./collector";
7
8
  export class SynchronousSemantic {
8
9
  generator;
9
10
  SynchronousSemantic = SynchronousSemanticSymbol;
11
+ [Symbol.toStringTag] = "SynchronousSemantic";
10
12
  constructor(generator) {
11
13
  if (isFunction(generator)) {
12
14
  this.generator = generator;
@@ -31,21 +33,22 @@ export class SynchronousSemantic {
31
33
  }
32
34
  concat(argument) {
33
35
  if (isSynchronousSemantic(argument)) {
34
- let other = argument;
35
36
  return new SynchronousSemantic((accept, interrupt) => {
36
37
  try {
38
+ let other = argument;
39
+ let generator = other.source();
37
40
  let count = 0n;
38
- this.generator((element, index) => {
39
- accept(element, index);
41
+ this.generator((element) => {
42
+ accept(element, count);
40
43
  count++;
41
44
  }, interrupt);
42
- let otherGenerator = Reflect.has(other, "generator") ? Reflect.get(other, "generator") : () => { };
43
- otherGenerator((element, index) => {
44
- accept(element, index + count);
45
+ generator((element) => {
46
+ accept(element, count);
47
+ count++;
45
48
  }, interrupt);
46
49
  }
47
50
  catch (error) {
48
- throw new Error("Uncaught error on concatenation.");
51
+ throw error;
49
52
  }
50
53
  });
51
54
  }
@@ -64,7 +67,7 @@ export class SynchronousSemantic {
64
67
  }
65
68
  }
66
69
  catch (error) {
67
- throw new Error("Uncaught error on concatenation.");
70
+ throw error;
68
71
  }
69
72
  });
70
73
  }
@@ -84,7 +87,7 @@ export class SynchronousSemantic {
84
87
  }, interrupt);
85
88
  }
86
89
  catch (error) {
87
- throw new Error("Uncaught error on distinct.");
90
+ throw error;
88
91
  }
89
92
  });
90
93
  }
@@ -106,7 +109,7 @@ export class SynchronousSemantic {
106
109
  }, interrupt);
107
110
  }
108
111
  catch (error) {
109
- throw new Error("Uncaught error on dropWhile.");
112
+ throw error;
110
113
  }
111
114
  });
112
115
  }
@@ -123,7 +126,7 @@ export class SynchronousSemantic {
123
126
  }, interrupt);
124
127
  }
125
128
  catch (error) {
126
- throw new Error("Uncaught error on filter.");
129
+ throw error;
127
130
  }
128
131
  });
129
132
  }
@@ -154,7 +157,7 @@ export class SynchronousSemantic {
154
157
  }, (element) => interrupt(element, count) || stop);
155
158
  }
156
159
  catch (error) {
157
- throw new Error("Uncaught error on flat.");
160
+ throw error;
158
161
  }
159
162
  });
160
163
  }
@@ -167,16 +170,16 @@ export class SynchronousSemantic {
167
170
  let count = 0n;
168
171
  let stop = false;
169
172
  this.generator((element, index) => {
170
- let result = mapper(element, index);
171
- if (isIterable(result)) {
172
- for (let subElement of result) {
173
+ let transform = mapper(element, index);
174
+ if (isIterable(transform)) {
175
+ for (let subElement of transform) {
173
176
  accept(subElement, count);
174
177
  stop = stop || interrupt(subElement, count);
175
178
  count++;
176
179
  }
177
180
  }
178
- else if (isSynchronousSemantic(result)) {
179
- result.generator((subElement) => {
181
+ else if (isSynchronousSemantic(transform)) {
182
+ transform.source()((subElement) => {
180
183
  accept(subElement, count);
181
184
  stop = stop || interrupt(subElement, count);
182
185
  count++;
@@ -185,44 +188,44 @@ export class SynchronousSemantic {
185
188
  }, () => stop);
186
189
  }
187
190
  catch (error) {
188
- throw new Error("Uncaught error on flatMap.");
191
+ throw error;
189
192
  }
190
193
  });
191
194
  }
192
195
  throw new TypeError("Invalid arguments.");
193
196
  }
194
- limit(n) {
195
- if (isNumber(n)) {
196
- let limit = BigInt(n);
197
+ limit(argument) {
198
+ if (isNumber(argument)) {
199
+ let limit = BigInt(argument);
197
200
  return new SynchronousSemantic((accept, interrupt) => {
198
201
  try {
199
202
  let count = 0n;
200
- this.generator((element, index) => {
203
+ this.generator((element) => {
201
204
  if (count < limit) {
202
- accept(element, index);
205
+ accept(element, count);
203
206
  count++;
204
207
  }
205
- }, (element) => interrupt(element, count) || count >= limit);
208
+ }, (element, index) => interrupt(element, index) || count >= limit);
206
209
  }
207
210
  catch (error) {
208
- throw new Error("Uncaught error on limit.");
211
+ throw error;
209
212
  }
210
213
  });
211
214
  }
212
- if (isBigInt(n)) {
213
- let limit = n;
215
+ if (isBigInt(argument)) {
216
+ let limit = argument;
214
217
  return new SynchronousSemantic((accept, interrupt) => {
215
218
  try {
216
219
  let count = 0n;
217
- this.generator((element, index) => {
220
+ this.generator((element) => {
218
221
  if (count < limit) {
219
- accept(element, index);
222
+ accept(element, count);
220
223
  count++;
221
224
  }
222
- }, (element) => interrupt(element, count) || count >= limit);
225
+ }, (element, index) => interrupt(element, index) || count >= limit);
223
226
  }
224
227
  catch (error) {
225
- throw new Error("Uncaught error on limit.");
228
+ throw error;
226
229
  }
227
230
  });
228
231
  }
@@ -240,7 +243,7 @@ export class SynchronousSemantic {
240
243
  }, () => stop);
241
244
  }
242
245
  catch (error) {
243
- throw new Error("Uncaught error on map.");
246
+ throw error;
244
247
  }
245
248
  });
246
249
  }
@@ -256,7 +259,7 @@ export class SynchronousSemantic {
256
259
  }, interrupt);
257
260
  }
258
261
  catch (error) {
259
- throw new Error("Uncaught error on peek.");
262
+ throw error;
260
263
  }
261
264
  });
262
265
  }
@@ -271,7 +274,7 @@ export class SynchronousSemantic {
271
274
  }, interrupt);
272
275
  }
273
276
  catch (error) {
274
- throw new Error("Uncaught error on redirect.");
277
+ throw error;
275
278
  }
276
279
  });
277
280
  }
@@ -285,22 +288,22 @@ export class SynchronousSemantic {
285
288
  }, interrupt);
286
289
  }
287
290
  catch (error) {
288
- throw new Error("Uncaught error on reverse.");
291
+ throw error;
289
292
  }
290
293
  });
291
294
  }
292
295
  shuffle(mapper) {
293
296
  if (isFunction(mapper)) {
294
- try {
295
- return new SynchronousSemantic((accept, interrupt) => {
297
+ return new SynchronousSemantic((accept, interrupt) => {
298
+ try {
296
299
  this.generator((element, index) => {
297
300
  accept(element, mapper(element, index));
298
301
  }, interrupt);
299
- });
300
- }
301
- catch (error) {
302
- throw new Error("Uncaught error on shuffle.");
303
- }
302
+ }
303
+ catch (error) {
304
+ throw error;
305
+ }
306
+ });
304
307
  }
305
308
  return new SynchronousSemantic((accept, interrupt) => {
306
309
  try {
@@ -309,12 +312,13 @@ export class SynchronousSemantic {
309
312
  }, interrupt);
310
313
  }
311
314
  catch (error) {
312
- throw new Error("Uncaught error on shuffle.");
315
+ throw error;
313
316
  }
314
317
  });
315
318
  }
316
- skip(n) {
317
- if (isNumber(n)) {
319
+ skip(argument) {
320
+ if (isNumber(argument)) {
321
+ let n = argument;
318
322
  return new SynchronousSemantic((accept, interrupt) => {
319
323
  try {
320
324
  let count = 0n;
@@ -329,11 +333,12 @@ export class SynchronousSemantic {
329
333
  }, interrupt);
330
334
  }
331
335
  catch (error) {
332
- throw new Error("Uncaught error on skip.");
336
+ throw error;
333
337
  }
334
338
  });
335
339
  }
336
- if (isBigInt(n)) {
340
+ if (isBigInt(argument)) {
341
+ let n = argument;
337
342
  return new SynchronousSemantic((accept, interrupt) => {
338
343
  try {
339
344
  let count = 0n;
@@ -347,7 +352,7 @@ export class SynchronousSemantic {
347
352
  }, interrupt);
348
353
  }
349
354
  catch (error) {
350
- throw new Error("Uncaught error on skip.");
355
+ throw error;
351
356
  }
352
357
  });
353
358
  }
@@ -356,73 +361,64 @@ export class SynchronousSemantic {
356
361
  source() {
357
362
  return this.generator;
358
363
  }
359
- sorted(comparator) {
360
- if (isFunction(comparator)) {
361
- try {
362
- return new SynchronousOrderedCollectable(this.generator, comparator);
363
- }
364
- catch (error) {
365
- throw new Error("Uncaught error on sorted.");
366
- }
367
- }
368
- try {
369
- return new SynchronousOrderedCollectable(this.generator, (a, b) => useCompare(a, b));
370
- }
371
- catch (error) {
372
- throw new Error("Uncaught error on sorted.");
373
- }
374
- }
375
364
  sub(start, end) {
376
- return new SynchronousSemantic((accept, interrupt) => {
377
- try {
378
- let count = 0n;
379
- this.generator((element, index) => {
380
- if (count < end) {
381
- count++;
382
- 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) {
383
375
  accept(element, index);
376
+ count++;
384
377
  }
385
- }
386
- }, interrupt);
387
- }
388
- catch (error) {
389
- throw new Error("Uncaught error on sub.");
390
- }
391
- });
378
+ }, (element, index) => count >= maximum || interrupt(element, index));
379
+ }
380
+ catch (error) {
381
+ throw error;
382
+ }
383
+ });
384
+ }
385
+ throw new TypeError("Invalid arguments.");
392
386
  }
393
387
  takeWhile(predicate) {
394
388
  return new SynchronousSemantic((accept, interrupt) => {
395
389
  try {
390
+ let stop = false;
396
391
  this.generator((element, index) => {
397
- if (!predicate(element, index)) {
398
- interrupt(element, index);
399
- return;
392
+ if (predicate(element, index) && stop === false) {
393
+ accept(element, index);
400
394
  }
401
- accept(element, index);
402
- }, interrupt);
395
+ else {
396
+ stop = true;
397
+ }
398
+ }, (element, index) => stop || interrupt(element, index));
403
399
  }
404
400
  catch (error) {
405
- throw new Error("Uncaught error on takeWhile.");
401
+ throw error;
406
402
  }
407
403
  });
408
404
  }
409
- toSynchronousCollectable(mapper) {
405
+ toCollectable(mapper) {
410
406
  if (isFunction(mapper)) {
411
407
  try {
412
- let synchronousCollectable = mapper(this.generator);
413
- if (isSynchronousCollectable(synchronousCollectable)) {
414
- return synchronousCollectable;
408
+ let SynchronousCollectable = mapper(this.generator);
409
+ if (isSynchronousCollectable(SynchronousCollectable)) {
410
+ return SynchronousCollectable;
415
411
  }
416
412
  }
417
413
  catch (error) {
418
- throw new Error("Uncaught error on toSynchronousCollectable.");
414
+ throw error;
419
415
  }
420
416
  }
421
417
  try {
422
418
  return new SynchronousUnorderedCollectable(this.generator);
423
419
  }
424
420
  catch (error) {
425
- throw new Error("Uncaught error on toSynchronousCollectable.");
421
+ throw error;
426
422
  }
427
423
  }
428
424
  toBigintStatistics() {
@@ -430,7 +426,7 @@ export class SynchronousSemantic {
430
426
  return new SynchronousBigIntStatistics(this.generator);
431
427
  }
432
428
  catch (error) {
433
- throw new Error("Uncaught error on toBigintStatistics.");
429
+ throw error;
434
430
  }
435
431
  }
436
432
  toNumericStatistics() {
@@ -438,7 +434,7 @@ export class SynchronousSemantic {
438
434
  return new SynchronousNumericStatistics(this.generator);
439
435
  }
440
436
  catch (error) {
441
- throw new Error("Uncaught error on toNumericStatistics.");
437
+ throw error;
442
438
  }
443
439
  }
444
440
  toOrdered() {
@@ -446,7 +442,7 @@ export class SynchronousSemantic {
446
442
  return new SynchronousOrderedCollectable(this.generator);
447
443
  }
448
444
  catch (error) {
449
- throw new Error("Uncaught error on toOrdered.");
445
+ throw error;
450
446
  }
451
447
  }
452
448
  toUnordered() {
@@ -454,7 +450,7 @@ export class SynchronousSemantic {
454
450
  return new SynchronousUnorderedCollectable(this.generator);
455
451
  }
456
452
  catch (error) {
457
- throw new Error(String(error));
453
+ throw error;
458
454
  }
459
455
  }
460
456
  toWindow() {
@@ -462,7 +458,7 @@ export class SynchronousSemantic {
462
458
  return new SynchronousWindowCollectable(this.generator);
463
459
  }
464
460
  catch (error) {
465
- throw new Error("Uncaught error on toWindow.");
461
+ throw error;
466
462
  }
467
463
  }
468
464
  translate(argument1) {
@@ -475,7 +471,7 @@ export class SynchronousSemantic {
475
471
  }, interrupt);
476
472
  }
477
473
  catch (error) {
478
- throw new Error("Uncaught error on translate.");
474
+ throw error;
479
475
  }
480
476
  });
481
477
  }
@@ -488,7 +484,7 @@ export class SynchronousSemantic {
488
484
  }, interrupt);
489
485
  }
490
486
  catch (error) {
491
- throw new Error("Uncaught error on translate.");
487
+ throw error;
492
488
  }
493
489
  });
494
490
  }
@@ -501,7 +497,7 @@ export class SynchronousSemantic {
501
497
  }, interrupt);
502
498
  }
503
499
  catch (error) {
504
- throw new Error("Uncaught error on translate.");
500
+ throw error;
505
501
  }
506
502
  });
507
503
  }
@@ -511,6 +507,7 @@ export class SynchronousSemantic {
511
507
  ;
512
508
  export class SynchronousCollectable {
513
509
  SynchronousCollectable = SynchronousCollectableSymbol;
510
+ [Symbol.toStringTag] = "SynchronousCollectable";
514
511
  constructor() {
515
512
  Object.defineProperty(this, "SynchronousCollectable", {
516
513
  value: SynchronousCollectableSymbol,
@@ -519,42 +516,47 @@ export class SynchronousCollectable {
519
516
  configurable: false
520
517
  });
521
518
  }
519
+ *[Symbol.iterator]() {
520
+ for (let element of this.toArray()) {
521
+ yield element;
522
+ }
523
+ }
522
524
  anyMatch(predicate) {
523
525
  if (isFunction(predicate)) {
524
526
  try {
525
- return useSynchronousAnyMatch(predicate).collect(this);
527
+ return useSynchronousAnyMatch(predicate).collect(this.source());
526
528
  }
527
529
  catch (error) {
528
- throw new Error("Uncaught error on anyMatch.");
530
+ throw error;
529
531
  }
530
532
  }
531
533
  throw new TypeError("Predicate must be a function.");
532
534
  }
533
535
  allMatch(predicate) {
534
- return useSynchronousAllMatch(predicate).collect(this);
536
+ return useSynchronousAllMatch(predicate).collect(this.source());
535
537
  }
536
538
  collect(argument1, argument2, argument3, argument4) {
537
539
  try {
538
- if (isAsynchronousCollector(argument1)) {
540
+ if (isSynchronousCollector(argument1)) {
539
541
  let collector = argument1;
540
- return collector.collect(this);
542
+ return collector.collect(this.source());
541
543
  }
542
544
  if (isFunction(argument1) && isFunction(argument2) && isFunction(argument3)) {
543
545
  let identity = argument1;
544
546
  let accumulator = argument2;
545
547
  let finisher = argument3;
546
- return useSynchronousCollect(identity, accumulator, finisher).collect(this);
548
+ return useSynchronousCollect(identity, accumulator, finisher).collect(this.source());
547
549
  }
548
550
  if (isFunction(argument1) && isFunction(argument2) && isFunction(argument3) && isFunction(argument4)) {
549
551
  let identity = argument1;
550
552
  let interrupt = argument2;
551
553
  let accumulator = argument3;
552
554
  let finisher = argument4;
553
- return useSynchronousCollect(identity, interrupt, accumulator, finisher).collect(this);
555
+ return useSynchronousCollect(identity, interrupt, accumulator, finisher).collect(this.source());
554
556
  }
555
557
  }
556
558
  catch (error) {
557
- throw new Error("Uncaught error on collect.");
559
+ throw error;
558
560
  }
559
561
  throw new TypeError("Invalid arguments.");
560
562
  }
@@ -567,7 +569,7 @@ export class SynchronousCollectable {
567
569
  useSynchronousError().collect(this.source());
568
570
  }
569
571
  catch (error) {
570
- throw new Error("Uncaught error on error.");
572
+ throw error;
571
573
  }
572
574
  }
573
575
  else if (isFunction(argument1) && invalidate(argument2) && invalidate(argument3)) {
@@ -576,7 +578,7 @@ export class SynchronousCollectable {
576
578
  useSynchronousError(accumulator).collect(this.source());
577
579
  }
578
580
  catch (error) {
579
- throw new Error("Uncaught error on error.");
581
+ throw error;
580
582
  }
581
583
  }
582
584
  else if (isString(argument1) && isFunction(argument2) && isString(argument3)) {
@@ -587,7 +589,7 @@ export class SynchronousCollectable {
587
589
  useSynchronousError(prefix, accumulator, suffix).collect(this.source());
588
590
  }
589
591
  catch (error) {
590
- throw new Error("Uncaught error on error.");
592
+ throw error;
591
593
  }
592
594
  }
593
595
  else {
@@ -602,7 +604,7 @@ export class SynchronousCollectable {
602
604
  return useSynchronousFindAny().collect(this.source());
603
605
  }
604
606
  catch (error) {
605
- throw new Error("Uncaught error on findAny.");
607
+ throw error;
606
608
  }
607
609
  }
608
610
  findAt(index) {
@@ -611,7 +613,7 @@ export class SynchronousCollectable {
611
613
  return useSynchronousFindAt(index).collect(this.source());
612
614
  }
613
615
  catch (error) {
614
- throw new Error("Uncaught error on findAt.");
616
+ throw error;
615
617
  }
616
618
  }
617
619
  else if (isNumber(index)) {
@@ -619,7 +621,7 @@ export class SynchronousCollectable {
619
621
  return useSynchronousFindAt(index).collect(this.source());
620
622
  }
621
623
  catch (error) {
622
- throw new Error("Uncaught error on findAt.");
624
+ throw error;
623
625
  }
624
626
  }
625
627
  throw new TypeError("Index must be a bigint.");
@@ -629,7 +631,7 @@ export class SynchronousCollectable {
629
631
  return useSynchronousFindFirst().collect(this.source());
630
632
  }
631
633
  catch (error) {
632
- throw new Error("Uncaught error on findFirst.");
634
+ throw error;
633
635
  }
634
636
  }
635
637
  findLast() {
@@ -637,7 +639,7 @@ export class SynchronousCollectable {
637
639
  return useSynchronousFindLast().collect(this.source());
638
640
  }
639
641
  catch (error) {
640
- throw new Error("Uncaught error on findLast.");
642
+ throw error;
641
643
  }
642
644
  }
643
645
  findMaximum(argument1) {
@@ -646,7 +648,7 @@ export class SynchronousCollectable {
646
648
  return useSynchronousFindMaximum(comparator).collect(this.source());
647
649
  }
648
650
  catch (error) {
649
- throw new Error("Uncaught error on findMaximum.");
651
+ throw error;
650
652
  }
651
653
  }
652
654
  findMinimum(argument1) {
@@ -655,16 +657,16 @@ export class SynchronousCollectable {
655
657
  return useSynchronousFindMinimum(comparator).collect(this.source());
656
658
  }
657
659
  catch (error) {
658
- throw new Error("Uncaught error on findMinimum.");
660
+ throw error;
659
661
  }
660
662
  }
661
663
  forEach(action) {
662
664
  if (isFunction(action)) {
663
665
  try {
664
- useSynchronousForEach(action).collect(this);
666
+ useSynchronousForEach(action).collect(this.source());
665
667
  }
666
668
  catch (error) {
667
- throw new Error("Uncaught error on forEach.");
669
+ throw error;
668
670
  }
669
671
  }
670
672
  else {
@@ -677,7 +679,7 @@ export class SynchronousCollectable {
677
679
  return useSynchronousGroup(classifier).collect(this.source());
678
680
  }
679
681
  catch (error) {
680
- throw new Error("Uncaught error on group.");
682
+ throw error;
681
683
  }
682
684
  }
683
685
  throw new TypeError("Classifier must be a function.");
@@ -688,7 +690,7 @@ export class SynchronousCollectable {
688
690
  return useSynchronousGroupBy(keyExtractor, valueExtractor).collect(this.source());
689
691
  }
690
692
  catch (error) {
691
- throw new Error("Uncaught error on groupBy.");
693
+ throw error;
692
694
  }
693
695
  }
694
696
  throw new TypeError("Key and value extractors must be functions.");
@@ -699,7 +701,7 @@ export class SynchronousCollectable {
699
701
  return useSynchronousJoin().collect(this.source());
700
702
  }
701
703
  catch (error) {
702
- throw new Error("Uncaught error on join.");
704
+ throw error;
703
705
  }
704
706
  }
705
707
  else if (isString(argument1) && invalidate(argument2) && invalidate(argument3)) {
@@ -708,7 +710,7 @@ export class SynchronousCollectable {
708
710
  return useSynchronousJoin(delimiter).collect(this.source());
709
711
  }
710
712
  catch (error) {
711
- throw new Error("Uncaught error on join.");
713
+ throw error;
712
714
  }
713
715
  }
714
716
  else if (isString(argument1) && isFunction(argument2) && isString(argument3)) {
@@ -719,7 +721,7 @@ export class SynchronousCollectable {
719
721
  return useSynchronousJoin(prefix, accumulator, suffix).collect(this.source());
720
722
  }
721
723
  catch (error) {
722
- throw new Error("Uncaught error on join.");
724
+ throw error;
723
725
  }
724
726
  }
725
727
  else if (isString(argument1) && isString(argument2) && isString(argument3)) {
@@ -730,7 +732,7 @@ export class SynchronousCollectable {
730
732
  return useSynchronousJoin(prefix, delimiter, suffix).collect(this.source());
731
733
  }
732
734
  catch (error) {
733
- throw new Error("Uncaught error on join.");
735
+ throw error;
734
736
  }
735
737
  }
736
738
  throw new TypeError("Invalid arguments.");
@@ -742,7 +744,7 @@ export class SynchronousCollectable {
742
744
  useSynchronousLog(accumulator).collect(this.source());
743
745
  }
744
746
  catch (error) {
745
- throw new Error("Uncaught error on log.");
747
+ throw error;
746
748
  }
747
749
  }
748
750
  else if (isString(argument1) && isFunction(argument2) && isString(argument3)) {
@@ -753,7 +755,7 @@ export class SynchronousCollectable {
753
755
  useSynchronousLog(prefix, accumulator, suffix).collect(this.source());
754
756
  }
755
757
  catch (error) {
756
- throw new Error("Uncaught error on log.");
758
+ throw error;
757
759
  }
758
760
  }
759
761
  else {
@@ -761,7 +763,7 @@ export class SynchronousCollectable {
761
763
  useSynchronousLog().collect(this.source());
762
764
  }
763
765
  catch (error) {
764
- throw new Error("Uncaught error on log.");
766
+ throw error;
765
767
  }
766
768
  }
767
769
  }
@@ -771,7 +773,7 @@ export class SynchronousCollectable {
771
773
  return useSynchronousNoneMatch(predicate).collect(this.source());
772
774
  }
773
775
  catch (error) {
774
- throw new Error("Uncaught error on nonMatch.");
776
+ throw error;
775
777
  }
776
778
  }
777
779
  throw new TypeError("Predicate must be a function.");
@@ -782,7 +784,7 @@ export class SynchronousCollectable {
782
784
  return useSynchronousPartition(count).collect(this.source());
783
785
  }
784
786
  catch (error) {
785
- throw new Error("Uncaught error on partition.");
787
+ throw error;
786
788
  }
787
789
  }
788
790
  throw new TypeError("Count must be a BigInt.");
@@ -794,7 +796,7 @@ export class SynchronousCollectable {
794
796
  return collector.collect(this.source());
795
797
  }
796
798
  catch (error) {
797
- throw new Error("Uncaught error on partitionBy.");
799
+ throw error;
798
800
  }
799
801
  }
800
802
  throw new TypeError("Classifier must be a function.");
@@ -806,7 +808,7 @@ export class SynchronousCollectable {
806
808
  return useSynchronousReduce(accumulator).collect(this.source());
807
809
  }
808
810
  catch (error) {
809
- throw new Error("Uncaught error on reduce.");
811
+ throw error;
810
812
  }
811
813
  }
812
814
  else if (validate(argument1) && isFunction(argument2) && invalidate(argument3)) {
@@ -816,7 +818,7 @@ export class SynchronousCollectable {
816
818
  return useSynchronousReduce(identity, accumulator).collect(this.source());
817
819
  }
818
820
  catch (error) {
819
- throw new Error("Uncaught error on reduce.");
821
+ throw error;
820
822
  }
821
823
  }
822
824
  else if (validate(argument1) && isFunction(argument2) && isFunction(argument3)) {
@@ -827,7 +829,7 @@ export class SynchronousCollectable {
827
829
  return useSynchronousReduce(identity, accumulator, finisher).collect(this.source());
828
830
  }
829
831
  catch (error) {
830
- throw new Error("Uncaught error on reduce.");
832
+ throw error;
831
833
  }
832
834
  }
833
835
  else {
@@ -841,7 +843,7 @@ export class SynchronousCollectable {
841
843
  return new SynchronousSemantic(source);
842
844
  }
843
845
  catch (error) {
844
- throw new Error("Uncaught error on semantic.");
846
+ throw error;
845
847
  }
846
848
  }
847
849
  else {
@@ -853,7 +855,7 @@ export class SynchronousCollectable {
853
855
  return useSynchronousToArray().collect(this.source());
854
856
  }
855
857
  catch (error) {
856
- throw new Error("Uncaught error on toArray.");
858
+ throw error;
857
859
  }
858
860
  }
859
861
  toMap(keyExtractor, valueExtractor = (element) => element) {
@@ -861,7 +863,7 @@ export class SynchronousCollectable {
861
863
  return useSynchronousToMap(keyExtractor, valueExtractor).collect(this.source());
862
864
  }
863
865
  catch (error) {
864
- throw new Error("Uncaught error on toMap.");
866
+ throw error;
865
867
  }
866
868
  }
867
869
  toSet() {
@@ -869,7 +871,7 @@ export class SynchronousCollectable {
869
871
  return useSynchronousToSet().collect(this.source());
870
872
  }
871
873
  catch (error) {
872
- throw new Error("Uncaught error on toSet.");
874
+ throw error;
873
875
  }
874
876
  }
875
877
  write(argument1, argument2) {
@@ -885,7 +887,7 @@ export class SynchronousCollectable {
885
887
  }
886
888
  }
887
889
  catch (error) {
888
- throw new Error("Uncaught error on write.");
890
+ throw error;
889
891
  }
890
892
  }
891
893
  throw new TypeError("Invalid arguments.");
@@ -893,31 +895,37 @@ export class SynchronousCollectable {
893
895
  }
894
896
  ;
895
897
  export class SynchronousOrderedCollectable extends SynchronousCollectable {
896
- SynchronousOrderedCollectable = SynchronousOrderedCollectableSymbol;
897
- buffer;
898
+ OrderedCollectable = SynchronousOrderedCollectableSymbol;
899
+ buffer = [];
900
+ [Symbol.toStringTag] = "SynchronousOrderedCollectable";
898
901
  constructor(argument1, argument2) {
899
902
  super();
900
903
  if (isFunction(argument1)) {
901
904
  try {
902
905
  if (isFunction(argument2)) {
903
906
  let collector = useSynchronousToArray();
904
- this.buffer = collector.collect(argument1).sort(argument2).map((element, index) => {
907
+ let generator = argument1;
908
+ let comparator = argument2;
909
+ this.buffer = collector.collect(generator).sort(comparator).map((element, index) => {
905
910
  return {
906
911
  element: element,
907
912
  index: BigInt(index)
908
913
  };
909
914
  });
915
+ Object.freeze(this.buffer);
910
916
  }
911
917
  else {
912
918
  let collector = useSynchronousToArray();
913
- this.buffer = collector.collect(argument1).map((element, index) => {
919
+ let generator = argument1;
920
+ this.buffer = collector.collect(generator).map((element, index, array) => {
914
921
  return {
915
922
  element: element,
916
- index: BigInt(index)
923
+ index: BigInt(((index % array.length) + array.length) % array.length)
917
924
  };
918
925
  }).sort((a, b) => {
919
926
  return Number(a.index - b.index);
920
927
  });
928
+ Object.freeze(this.buffer);
921
929
  }
922
930
  Object.defineProperties(this, {
923
931
  "SynchronousOrderedCollectable": {
@@ -943,47 +951,35 @@ export class SynchronousOrderedCollectable extends SynchronousCollectable {
943
951
  }
944
952
  }
945
953
  *[Symbol.iterator]() {
946
- try {
947
- for (let indexed of this.buffer) {
948
- yield indexed.element;
949
- }
950
- }
951
- catch (error) {
952
- throw new Error("Uncaught error on Generator.");
954
+ for (let { element } of this.buffer) {
955
+ yield element;
953
956
  }
954
957
  }
955
- async *[Symbol.asyncIterator]() {
956
- try {
957
- for (let indexed of this.buffer) {
958
- yield indexed.element;
959
- }
960
- }
961
- catch (error) {
962
- throw new Error("Uncaught error on AsyncGenerator.");
963
- }
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);
964
961
  }
965
962
  source() {
966
- try {
967
- return (accept, interrupt) => {
968
- for (let indexed of this.buffer) {
969
- if (interrupt(indexed.element, indexed.index)) {
970
- break;
971
- }
972
- accept(indexed.element, indexed.index);
963
+ return (accept, interrupt) => {
964
+ for (let { element, index } of this.buffer) {
965
+ if (interrupt(element, index)) {
966
+ break;
973
967
  }
974
- };
975
- }
976
- catch (error) {
977
- throw new Error("Uncaught error on creating source.");
978
- }
968
+ accept(element, index);
969
+ }
970
+ };
979
971
  }
980
972
  isEmpty() {
981
973
  return this.buffer.length === 0;
982
974
  }
975
+ count() {
976
+ return BigInt(this.buffer.length);
977
+ }
983
978
  }
984
979
  ;
985
980
  export class SynchronousUnorderedCollectable extends SynchronousCollectable {
986
981
  SynchronousUnorderedCollectable = SynchronousUnorderedCollectableSymbol;
982
+ [Symbol.toStringTag] = "SynchronousUnorderedCollectable";
987
983
  buffer = new Map();
988
984
  constructor(argument1) {
989
985
  super();
@@ -992,6 +988,7 @@ export class SynchronousUnorderedCollectable extends SynchronousCollectable {
992
988
  generator((element, index) => {
993
989
  this.buffer.set(index, element);
994
990
  }, () => false);
991
+ Object.freeze(this.buffer);
995
992
  Object.defineProperties(this, {
996
993
  "SynchronousUnorderedCollectable": {
997
994
  value: SynchronousUnorderedCollectableSymbol,
@@ -1005,40 +1002,26 @@ export class SynchronousUnorderedCollectable extends SynchronousCollectable {
1005
1002
  throw new TypeError("Source must be an iterable or a generator function.");
1006
1003
  }
1007
1004
  }
1005
+ *[Symbol.iterator]() {
1006
+ for (let [_index, element] of this.buffer) {
1007
+ yield element;
1008
+ }
1009
+ }
1008
1010
  source() {
1009
1011
  return (accept, interrupt) => {
1010
- for (let [index, element] of this.buffer) {
1011
- if (interrupt(element, index)) {
1012
+ for (let [_index, element] of this.buffer) {
1013
+ if (interrupt(element, _index)) {
1012
1014
  break;
1013
1015
  }
1014
- accept(element, index);
1016
+ accept(element, _index);
1015
1017
  }
1016
1018
  };
1017
1019
  }
1018
- *[Symbol.iterator]() {
1019
- try {
1020
- for (let [_index, element] of this.buffer) {
1021
- yield element;
1022
- }
1023
- }
1024
- catch (error) {
1025
- throw new Error("Uncaught error on Generator.");
1026
- }
1027
- }
1028
- async *[Symbol.asyncIterator]() {
1029
- try {
1030
- for (let [_index, element] of this.buffer) {
1031
- yield element;
1032
- }
1033
- }
1034
- catch (error) {
1035
- throw new Error("Uncaught error on AsyncGenerator.");
1036
- }
1037
- }
1038
1020
  }
1039
1021
  ;
1040
1022
  export class SynchronousStatistics extends SynchronousOrderedCollectable {
1041
1023
  SynchronousStatistics = SynchronousStatisticsSymbol;
1024
+ [Symbol.toStringTag] = "SynchronousStatistics";
1042
1025
  constructor(parameter, comparator) {
1043
1026
  super(parameter, validate(comparator) ? comparator : useCompare);
1044
1027
  Object.defineProperties(this, {
@@ -1051,27 +1034,9 @@ export class SynchronousStatistics extends SynchronousOrderedCollectable {
1051
1034
  });
1052
1035
  }
1053
1036
  *[Symbol.iterator]() {
1054
- try {
1055
- for (let indexed of this.buffer) {
1056
- yield indexed.element;
1057
- }
1058
- }
1059
- catch (error) {
1060
- throw new Error("Uncaught error on Generator.");
1061
- }
1062
- }
1063
- async *[Symbol.asyncIterator]() {
1064
- try {
1065
- for (let indexed of this.buffer) {
1066
- yield indexed.element;
1067
- }
1037
+ for (let { element } of this.buffer) {
1038
+ yield element;
1068
1039
  }
1069
- catch (error) {
1070
- throw new Error("Uncaught error on AsyncGenerator.");
1071
- }
1072
- }
1073
- count() {
1074
- return BigInt(this.buffer.length);
1075
1040
  }
1076
1041
  frequency() {
1077
1042
  return useSynchronousFrequency().collect(this.source());
@@ -1080,6 +1045,7 @@ export class SynchronousStatistics extends SynchronousOrderedCollectable {
1080
1045
  ;
1081
1046
  export class SynchronousBigIntStatistics extends SynchronousStatistics {
1082
1047
  BigIntStatistics = SynchronousBigIntStatisticsSymbol;
1048
+ [Symbol.toStringTag] = "SynchronousBigIntStatistics";
1083
1049
  constructor(parameter, comparator) {
1084
1050
  super(parameter, comparator || useCompare);
1085
1051
  Object.defineProperties(this, {
@@ -1092,23 +1058,8 @@ export class SynchronousBigIntStatistics extends SynchronousStatistics {
1092
1058
  });
1093
1059
  }
1094
1060
  *[Symbol.iterator]() {
1095
- try {
1096
- for (let indexed of this.buffer) {
1097
- yield indexed.element;
1098
- }
1099
- }
1100
- catch (error) {
1101
- throw new Error("Uncaught error on Generator.");
1102
- }
1103
- }
1104
- async *[Symbol.asyncIterator]() {
1105
- try {
1106
- for (let indexed of this.buffer) {
1107
- yield indexed.element;
1108
- }
1109
- }
1110
- catch (error) {
1111
- throw new Error("Uncaught error on AsyncGenerator.");
1061
+ for (let { element } of this.buffer) {
1062
+ yield element;
1112
1063
  }
1113
1064
  }
1114
1065
  average(argument1) {
@@ -1129,10 +1080,14 @@ export class SynchronousBigIntStatistics extends SynchronousStatistics {
1129
1080
  }
1130
1081
  try {
1131
1082
  let mapper = isFunction(argument1) ? argument1 : useToBigInt;
1132
- let count = this.buffer.length;
1133
- let minimum = this.buffer[0].element;
1134
- let maximum = this.buffer[count - 1].element;
1135
- return mapper(maximum) - mapper(minimum);
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);
1136
1091
  }
1137
1092
  catch (error) {
1138
1093
  throw new Error("Uncaught error on range.");
@@ -1212,7 +1167,7 @@ export class SynchronousBigIntStatistics extends SynchronousStatistics {
1212
1167
  if (this.isEmpty()) {
1213
1168
  return 0n;
1214
1169
  }
1215
- if (typeof quantile !== "number" || quantile < 0 || quantile > 1) {
1170
+ if (!isNumber(quantile) || quantile < 0 || quantile > 1) {
1216
1171
  throw new RangeError("Invalid quantile.");
1217
1172
  }
1218
1173
  try {
@@ -1222,8 +1177,7 @@ export class SynchronousBigIntStatistics extends SynchronousStatistics {
1222
1177
  if (index === count) {
1223
1178
  index--;
1224
1179
  }
1225
- let value = mapper(this.buffer[index].element);
1226
- return value;
1180
+ return this.findAt(index).map(mapper).get(0n);
1227
1181
  }
1228
1182
  catch (error) {
1229
1183
  throw new Error("Uncaught error on quantile.");
@@ -1254,7 +1208,7 @@ export class SynchronousBigIntStatistics extends SynchronousStatistics {
1254
1208
  if (standardDeviation === 0n) {
1255
1209
  return 0n;
1256
1210
  }
1257
- let data = this.toArray().map(item => mapper(item));
1211
+ let data = (this.toArray()).map((element) => mapper(element));
1258
1212
  let summate = 0n;
1259
1213
  for (let value of data) {
1260
1214
  let z = value - mean;
@@ -1277,7 +1231,7 @@ export class SynchronousBigIntStatistics extends SynchronousStatistics {
1277
1231
  if (standardDeviation === 0n) {
1278
1232
  return 0n;
1279
1233
  }
1280
- let data = this.toArray().map(item => mapper(item));
1234
+ let data = (this.toArray()).map((element) => mapper(element));
1281
1235
  let summate = 0n;
1282
1236
  let count = data.length;
1283
1237
  for (let value of data) {
@@ -1294,6 +1248,7 @@ export class SynchronousBigIntStatistics extends SynchronousStatistics {
1294
1248
  ;
1295
1249
  export class SynchronousNumericStatistics extends SynchronousStatistics {
1296
1250
  SynchronousNumericStatistics = SynchronousNumericStatisticsSymbol;
1251
+ [Symbol.toStringTag] = "SynchronousNumericStatistics";
1297
1252
  constructor(parameter, comparator) {
1298
1253
  super(parameter, comparator || useCompare);
1299
1254
  Object.defineProperties(this, {
@@ -1306,23 +1261,8 @@ export class SynchronousNumericStatistics extends SynchronousStatistics {
1306
1261
  });
1307
1262
  }
1308
1263
  *[Symbol.iterator]() {
1309
- try {
1310
- for (let indexed of this.buffer) {
1311
- yield indexed.element;
1312
- }
1313
- }
1314
- catch (error) {
1315
- throw new Error("Uncaught error on Generator.");
1316
- }
1317
- }
1318
- async *[Symbol.asyncIterator]() {
1319
- try {
1320
- for (let indexed of this.buffer) {
1321
- yield indexed.element;
1322
- }
1323
- }
1324
- catch (error) {
1325
- throw new Error("Uncaught error on AsyncGenerator.");
1264
+ for (let { element } of this.buffer) {
1265
+ yield element;
1326
1266
  }
1327
1267
  }
1328
1268
  average(mapper) {
@@ -1348,10 +1288,14 @@ export class SynchronousNumericStatistics extends SynchronousStatistics {
1348
1288
  return 0;
1349
1289
  }
1350
1290
  let mapper = isFunction(argument1) ? argument1 : useToNumber;
1351
- let count = this.buffer.length;
1352
- let minimum = this.buffer[0].element;
1353
- let maximum = this.buffer[count - 1].element;
1354
- return mapper(maximum) - mapper(minimum);
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);
1355
1299
  }
1356
1300
  catch (error) {
1357
1301
  throw new Error("Uncaught error on range.");
@@ -1440,8 +1384,7 @@ export class SynchronousNumericStatistics extends SynchronousStatistics {
1440
1384
  if (index === count) {
1441
1385
  index--;
1442
1386
  }
1443
- let value = mapper(this.buffer[index].element);
1444
- return value;
1387
+ return this.findAt(index).map(mapper).get(0);
1445
1388
  }
1446
1389
  catch (error) {
1447
1390
  throw new Error("Uncaught error on quantile.");
@@ -1472,7 +1415,7 @@ export class SynchronousNumericStatistics extends SynchronousStatistics {
1472
1415
  if (standardDeviation === 0) {
1473
1416
  return 0;
1474
1417
  }
1475
- let data = this.toArray().map(item => mapper(item));
1418
+ let data = (this.toArray()).map((element) => mapper(element));
1476
1419
  let summate = 0;
1477
1420
  for (let value of data) {
1478
1421
  let z = (value - mean) / standardDeviation;
@@ -1495,7 +1438,7 @@ export class SynchronousNumericStatistics extends SynchronousStatistics {
1495
1438
  if (standardDeviation === 0) {
1496
1439
  return 0;
1497
1440
  }
1498
- let data = this.toArray().map(item => mapper(item));
1441
+ let data = (this.toArray()).map((element) => mapper(element));
1499
1442
  let summate = 0;
1500
1443
  for (let value of data) {
1501
1444
  let z = (value - mean) / standardDeviation;
@@ -1511,6 +1454,7 @@ export class SynchronousNumericStatistics extends SynchronousStatistics {
1511
1454
  ;
1512
1455
  export class SynchronousWindowCollectable extends SynchronousOrderedCollectable {
1513
1456
  WindowCollectable = SynchronousWindowCollectableSymbol;
1457
+ [Symbol.toStringTag] = "SynchronousWindowCollectable";
1514
1458
  constructor(parameter, comparator = useCompare) {
1515
1459
  super(parameter, comparator);
1516
1460
  Object.defineProperties(this, {
@@ -1523,23 +1467,8 @@ export class SynchronousWindowCollectable extends SynchronousOrderedCollectable
1523
1467
  });
1524
1468
  }
1525
1469
  *[Symbol.iterator]() {
1526
- try {
1527
- for (let indexed of this.buffer) {
1528
- yield indexed.element;
1529
- }
1530
- }
1531
- catch (error) {
1532
- throw new Error("Uncaught error on Generator.");
1533
- }
1534
- }
1535
- async *[Symbol.asyncIterator]() {
1536
- try {
1537
- for (let indexed of this.buffer) {
1538
- yield indexed.element;
1539
- }
1540
- }
1541
- catch (error) {
1542
- throw new Error("Uncaught error on AsyncGenerator.");
1470
+ for (let { element } of this.buffer) {
1471
+ yield element;
1543
1472
  }
1544
1473
  }
1545
1474
  slide(size, step = 1n) {