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,15 +1,14 @@
1
- import { Collectable } from "./semantic";
2
- import { isBigInt, isBoolean, isCollectable, isFunction, isIterable, isNumber, isObject, isSemantic, isString } from "./guard";
3
- import { useCompare, useToBigInt, useToNumber } from "./hook";
4
- import { Optional } from "./optional";
5
- import { CollectableSymbol } from "./symbol";
6
- import { validate, invalidate } from "./utility";
7
- export class Collector {
1
+ import { isFunction, isNumber, isBigInt, isBoolean, isString, isObject, isAsyncFunction, isIterable } from "../guard";
2
+ import { useCompare, useToBigInt, useToNumber } from "../hook";
3
+ import { Optional } from "../optional";
4
+ import { SynchronousCollectorSymbol } from "../symbol";
5
+ import { invalidate, validate } from "../utility";
6
+ export class SynchronousCollector {
8
7
  identity;
9
8
  interrupt;
10
9
  accumulator;
11
10
  finisher;
12
- Collector = CollectableSymbol;
11
+ SynchronousCollector = SynchronousCollectorSymbol;
13
12
  constructor(identity, interrupt, accumulator, finisher) {
14
13
  if (isFunction(identity) && isFunction(interrupt) && isFunction(accumulator) && isFunction(finisher)) {
15
14
  this.identity = identity;
@@ -41,8 +40,8 @@ export class Collector {
41
40
  enumerable: true,
42
41
  configurable: false
43
42
  },
44
- "Collector": {
45
- value: CollectableSymbol,
43
+ "SynchronousCollector": {
44
+ value: SynchronousCollectorSymbol,
46
45
  writable: false,
47
46
  enumerable: false,
48
47
  configurable: false
@@ -55,124 +54,140 @@ export class Collector {
55
54
  }
56
55
  }
57
56
  collect(argument1, argument2) {
58
- let accumulator = this.identity();
59
- let count = 0n;
60
- if (isFunction(argument1)) {
61
- let generator = argument1;
62
- generator((element, index) => {
63
- accumulator = this.accumulator(accumulator, element, index);
64
- count++;
65
- }, (element, index) => this.interrupt(element, index, accumulator));
66
- }
67
- else if (isIterable(argument1)) {
68
- let iterable = argument1;
69
- let index = 0n;
70
- for (let element of iterable) {
71
- if (this.interrupt(element, index, accumulator)) {
72
- break;
73
- }
74
- accumulator = this.accumulator(accumulator, element, count);
75
- count++;
76
- index++;
77
- }
78
- }
79
- else if (isSemantic(argument1)) {
80
- let semantic = argument1;
81
- let generator = Reflect.get(semantic, "generator");
82
- if (isFunction(generator)) {
57
+ if (isAsyncFunction(argument1) || isFunction(argument1)) {
58
+ try {
59
+ let generator = argument1;
60
+ let accumulator = this.identity();
61
+ let count = 0n;
83
62
  generator((element, index) => {
84
63
  accumulator = this.accumulator(accumulator, element, index);
85
64
  count++;
86
65
  }, (element, index) => this.interrupt(element, index, accumulator));
66
+ return this.finisher(accumulator);
87
67
  }
88
- else {
89
- throw new TypeError("Invalid arguments");
68
+ catch (error) {
69
+ throw error;
90
70
  }
91
71
  }
92
- else if (isCollectable(argument1)) {
93
- let collectable = argument1;
94
- let source = collectable.source();
95
- if (isFunction(source)) {
96
- let generator = source;
97
- generator((element, index) => {
98
- accumulator = this.accumulator(accumulator, element, index);
72
+ else if (isIterable(argument1)) {
73
+ try {
74
+ let iterable = argument1;
75
+ let accumulator = this.identity();
76
+ let count = 0n;
77
+ for (let element of iterable) {
78
+ if (this.interrupt(element, count, accumulator)) {
79
+ break;
80
+ }
81
+ accumulator = this.accumulator(accumulator, element, count);
99
82
  count++;
100
- }, (element, index) => this.interrupt(element, index, accumulator));
83
+ }
84
+ return this.finisher(accumulator);
85
+ }
86
+ catch (error) {
87
+ throw error;
101
88
  }
102
89
  }
103
90
  else if (isNumber(argument1) && isNumber(argument2)) {
104
- let start = argument1 < argument2 ? argument1 : argument2;
105
- let end = argument1 > argument2 ? argument1 : argument2;
106
- for (let i = start; i < end; i++) {
107
- if (this.interrupt(i, count, accumulator)) {
108
- break;
91
+ try {
92
+ let start = argument1 < argument2 ? argument1 : argument2;
93
+ let end = argument1 > argument2 ? argument1 : argument2;
94
+ let accumulator = this.identity();
95
+ let count = 0n;
96
+ for (let i = start; i < end; i++) {
97
+ if (this.interrupt(i, count, accumulator)) {
98
+ break;
99
+ }
100
+ accumulator = this.accumulator(accumulator, i, count);
101
+ count++;
109
102
  }
110
- accumulator = this.accumulator(accumulator, i, count);
111
- count++;
103
+ return this.finisher(accumulator);
104
+ }
105
+ catch (error) {
106
+ throw error;
112
107
  }
113
108
  }
114
109
  else if (isBigInt(argument1) && isBigInt(argument2)) {
115
- let start = argument1 < argument2 ? argument1 : argument2;
116
- let end = argument1 > argument2 ? argument1 : argument2;
117
- for (let i = start; i < end; i++) {
118
- if (this.interrupt(i, count, accumulator)) {
119
- break;
110
+ try {
111
+ let start = argument1 < argument2 ? argument1 : argument2;
112
+ let end = argument1 > argument2 ? argument1 : argument2;
113
+ let accumulator = this.identity();
114
+ let count = 0n;
115
+ for (let i = start; i < end; i++) {
116
+ if (this.interrupt(i, count, accumulator)) {
117
+ break;
118
+ }
119
+ accumulator = this.accumulator(accumulator, i, count);
120
+ count++;
120
121
  }
121
- accumulator = this.accumulator(accumulator, i, count);
122
- count++;
122
+ return this.finisher(accumulator);
123
+ }
124
+ catch (error) {
125
+ throw error;
123
126
  }
124
127
  }
125
- return this.finisher(accumulator);
128
+ throw new Error("Invalid arguments.");
129
+ }
130
+ getIdentity() {
131
+ return this.identity;
132
+ }
133
+ getInterrupt() {
134
+ return this.interrupt;
135
+ }
136
+ getAccumulator() {
137
+ return this.accumulator;
138
+ }
139
+ getFinisher() {
140
+ return this.finisher;
126
141
  }
127
142
  static full(identity, accumulator, finisher) {
128
- return new Collector(identity, () => false, accumulator, finisher);
143
+ return new SynchronousCollector(identity, () => false, accumulator, finisher);
129
144
  }
130
145
  static shortable(identity, interrupt, accumulator, finisher) {
131
- return new Collector(identity, interrupt, accumulator, finisher);
146
+ return new SynchronousCollector(identity, interrupt, accumulator, finisher);
132
147
  }
133
148
  }
134
149
  ;
135
150
  ;
136
- export let useAnyMatch = (predicate) => {
151
+ export let useSynchronousAnyMatch = (predicate) => {
137
152
  if (isFunction(predicate)) {
138
- return Collector.shortable(() => false, (_element, _index, accumulator) => isBoolean(accumulator) && accumulator, (accumulator, element, index) => accumulator || predicate(element, index), (accumulator) => accumulator);
153
+ return SynchronousCollector.shortable(() => false, (_element, _index, accumulator) => isBoolean(accumulator) && accumulator, (accumulator, element, index) => accumulator || predicate(element, index), (accumulator) => accumulator);
139
154
  }
140
155
  throw new TypeError("Predicate must be a function.");
141
156
  };
142
157
  ;
143
- export let useAllMatch = (predicate) => {
158
+ export let useSynchronousAllMatch = (predicate) => {
144
159
  if (isFunction(predicate)) {
145
- return Collector.shortable(() => true, (_element, _index, accumulator) => isBoolean(accumulator) && !accumulator, (accumulator, element, index) => accumulator && predicate(element, index), (accumulator) => accumulator);
160
+ return SynchronousCollector.shortable(() => true, (_element, _index, accumulator) => isBoolean(accumulator) && !accumulator, (accumulator, element, index) => accumulator && predicate(element, index), (accumulator) => accumulator);
146
161
  }
147
162
  throw new TypeError("Predicate must be a function.");
148
163
  };
149
164
  ;
150
- export let useCollect = (argument1, argument2, argument3, argument4) => {
165
+ export let useSynchronousCollect = (argument1, argument2, argument3, argument4) => {
151
166
  if (isFunction(argument1) && isFunction(argument2) && isFunction(argument3) && isFunction(argument4)) {
152
167
  let identity = argument1;
153
168
  let interrupt = argument2;
154
169
  let accumulator = argument3;
155
170
  let finisher = argument4;
156
- return Collector.shortable(identity, interrupt, accumulator, finisher);
171
+ return SynchronousCollector.shortable(identity, interrupt, accumulator, finisher);
157
172
  }
158
173
  if (isFunction(argument1) && isFunction(argument2) && isFunction(argument3)) {
159
174
  let identity = argument1;
160
175
  let accumulator = argument2;
161
176
  let finisher = argument3;
162
- return Collector.full(identity, accumulator, finisher);
177
+ return SynchronousCollector.full(identity, accumulator, finisher);
163
178
  }
164
179
  throw new TypeError("Identity, accumulator, and finisher must be functions.");
165
180
  };
166
- export let useCount = () => {
167
- return Collector.full(() => 0n, (count) => count + 1n, (count) => count);
181
+ export let useSynchronousCount = () => {
182
+ return SynchronousCollector.full(() => 0n, (count) => isBigInt(count) ? (count + 1n) : 1n, (count) => isBigInt(count) ? count : 0n);
168
183
  };
169
184
  ;
170
- export let useError = (argument1, argument2, argument3) => {
185
+ export let useSynchronousError = (argument1, argument2, argument3) => {
171
186
  if (isString(argument1) && isFunction(argument2) && isString(argument3)) {
172
187
  let prefix = argument1;
173
188
  let accumulator = argument2;
174
189
  let suffix = argument3;
175
- return Collector.full(() => prefix, accumulator, (text) => {
190
+ return SynchronousCollector.full(() => prefix, accumulator, (text) => {
176
191
  let result = text + suffix;
177
192
  console.error(result);
178
193
  return result;
@@ -182,14 +197,14 @@ export let useError = (argument1, argument2, argument3) => {
182
197
  let prefix = "[";
183
198
  let accumulator = argument2;
184
199
  let suffix = "]";
185
- return Collector.full(() => prefix, accumulator, (text) => {
200
+ return SynchronousCollector.full(() => prefix, accumulator, (text) => {
186
201
  let result = text + suffix;
187
202
  console.error(result);
188
203
  return result;
189
204
  });
190
205
  }
191
206
  else {
192
- return Collector.full(() => "[", (accumulator, element) => {
207
+ return SynchronousCollector.full(() => "[", (accumulator, element) => {
193
208
  if (isString(accumulator) && isString(element)) {
194
209
  return accumulator + element + ",";
195
210
  }
@@ -202,74 +217,87 @@ export let useError = (argument1, argument2, argument3) => {
202
217
  }
203
218
  };
204
219
  ;
205
- export let useFindAt = (index) => {
220
+ export let useSynchronousFindAt = (index) => {
206
221
  let target = useToBigInt(index);
207
222
  if (target < 0n) {
208
- return Collector.full(() => [], (accumulator, element) => {
209
- accumulator.push(element);
210
- return accumulator;
211
- }, (accumulator) => {
212
- if (accumulator.length === 0) {
213
- return Optional.empty();
223
+ return SynchronousCollector.full(() => [], (accumulator, element) => {
224
+ let accumulated = Array.isArray(accumulator) ? accumulator : [];
225
+ accumulated.push(element);
226
+ return accumulated;
227
+ }, (result) => {
228
+ if (Array.isArray(result) && result.length > 0) {
229
+ let index = ((Number(target) % result.length) + result.length) % result.length;
230
+ return Optional.of(result[index]);
214
231
  }
215
- let limited = (((BigInt(accumulator.length)) % target) + target) % target;
216
- return Optional.ofNullable(accumulator[Number(limited)]);
232
+ return Optional.empty();
217
233
  });
218
234
  }
219
- return Collector.shortable(() => [], (_element, _index, accumulator) => BigInt(accumulator.length) - 1n === target, (accumulator, element) => {
220
- accumulator.push(element);
221
- return accumulator;
222
- }, (accumulator) => {
223
- if (accumulator.length === 0) {
224
- return Optional.empty();
235
+ return SynchronousCollector.shortable(() => [], (_element, _index, accumulator) => BigInt(accumulator.length) - 1n === target, (accumulator, element) => {
236
+ let accumulated = Array.isArray(accumulator) ? accumulator : [];
237
+ accumulated.push(element);
238
+ return accumulated;
239
+ }, (result) => {
240
+ let index = ((Number(target) % result.length) + result.length) % result.length;
241
+ if (Array.isArray(result) && result.length > 0) {
242
+ return Optional.of(result[index]);
225
243
  }
226
- return Optional.ofNullable(accumulator[Number(target)]);
244
+ return Optional.empty();
227
245
  });
228
246
  };
229
- export let useFindFirst = () => {
230
- return Collector.shortable(() => Optional.empty(), (_element, _index, accumulator) => validate(accumulator) && accumulator.isPresent(), (accumulator, element) => {
231
- if (validate(accumulator) && accumulator.isPresent()) {
232
- return accumulator;
233
- }
234
- return Optional.ofNullable(element);
235
- }, (accumulator) => accumulator);
236
- };
237
- export let useFindAny = () => {
238
- return Collector.shortable(() => Optional.empty(), (_element, _index, accumulator) => validate(accumulator) && accumulator.isPresent(), (accumulator, element) => {
239
- if (validate(accumulator) && accumulator.isPresent() && Math.random() < 0.5) {
240
- return accumulator;
241
- }
242
- return Optional.ofNullable(element);
243
- }, (accumulator) => accumulator);
244
- };
245
- export let useFindLast = () => {
246
- return Collector.full(() => Optional.empty(), (accumulator, element) => {
247
- if (validate(accumulator) && accumulator.isPresent()) {
248
- return Optional.ofNullable(element);
247
+ export let useSynchronousFindFirst = () => {
248
+ return SynchronousCollector.shortable(() => Optional.empty(), (_element, _index, accumulator) => validate(accumulator) && accumulator.isPresent(), (accumulator, element) => {
249
+ if (validate(accumulator) && accumulator.isPresent() && validate(element)) {
250
+ return Optional.of(element);
249
251
  }
250
252
  return accumulator;
251
- }, (accumulator) => accumulator);
253
+ }, (result) => result);
252
254
  };
253
- export let useFindMaximum = (comparator = (useCompare)) => {
254
- return Collector.full(() => Optional.ofNullable(), (accumulator, element) => {
255
- if (accumulator.isPresent()) {
256
- return comparator(accumulator.get(), element) > 0 ? accumulator : Optional.ofNullable(element);
255
+ export let useSynchronousFindAny = () => {
256
+ return SynchronousCollector.shortable(() => Optional.empty(), (_element, _index, accumulator) => validate(accumulator) && accumulator.isPresent(), (accumulator, element) => {
257
+ if (validate(accumulator) && accumulator.isPresent() && validate(element) && Math.random() < 0.5) {
258
+ return Optional.of(element);
257
259
  }
258
- return Optional.ofNullable(element);
260
+ return accumulator;
259
261
  }, (result) => result);
260
262
  };
261
- export let useFindMinimum = (comparator = (useCompare)) => {
262
- return Collector.full(() => Optional.ofNullable(), (accumulator, element) => {
263
- if (accumulator.isPresent()) {
264
- return comparator(accumulator.get(), element) < 0 ? accumulator : Optional.ofNullable(element);
263
+ export let useSynchronousFindLast = () => {
264
+ return SynchronousCollector.full(() => Optional.empty(), (accumulator, element) => {
265
+ if (validate(accumulator) && accumulator.isPresent() && validate(element)) {
266
+ return Optional.of(element);
265
267
  }
266
- return Optional.ofNullable(element);
268
+ return accumulator;
267
269
  }, (result) => result);
268
270
  };
271
+ export let useSynchronousFindMaximum = (comparator = (useCompare)) => {
272
+ if (isFunction(comparator)) {
273
+ return SynchronousCollector.full(() => Optional.empty(), (accumulator, element) => {
274
+ if (validate(accumulator) && accumulator.isPresent()) {
275
+ return accumulator.map((previous) => {
276
+ return comparator(previous, element) > 0 ? previous : element;
277
+ });
278
+ }
279
+ return accumulator;
280
+ }, (result) => result);
281
+ }
282
+ throw new TypeError("Invalid argument.");
283
+ };
284
+ export let useSynchronousFindMinimum = (comparator = (useCompare)) => {
285
+ if (isFunction(comparator)) {
286
+ return SynchronousCollector.full(() => Optional.empty(), (accumulator, element) => {
287
+ if (validate(accumulator) && accumulator.isPresent()) {
288
+ return accumulator.map((previous) => {
289
+ return comparator(previous, element) < 0 ? previous : element;
290
+ });
291
+ }
292
+ return accumulator;
293
+ }, (result) => result);
294
+ }
295
+ throw new TypeError("Invalid argument.");
296
+ };
269
297
  ;
270
- export let useForEach = (action) => {
298
+ export let useSynchronousForEach = (action) => {
271
299
  if (isFunction(action)) {
272
- return Collector.full(() => 0n, (accumulator, element, index) => {
300
+ return SynchronousCollector.full(() => 0n, (accumulator, element, index) => {
273
301
  action(element, index);
274
302
  return accumulator + 1n;
275
303
  }, (accumulator) => accumulator);
@@ -277,16 +305,16 @@ export let useForEach = (action) => {
277
305
  throw new TypeError("Action must be a function.");
278
306
  };
279
307
  ;
280
- export let useNoneMatch = (predicate) => {
308
+ export let useSynchronousNoneMatch = (predicate) => {
281
309
  if (isFunction(predicate)) {
282
- return Collector.shortable(() => true, (_element, _index, accumulator) => !accumulator, (accumulator, element, index) => accumulator && !predicate(element, index), (accumulator) => !accumulator);
310
+ return SynchronousCollector.shortable(() => true, (_element, _index, accumulator) => !accumulator, (accumulator, element, index) => accumulator && !predicate(element, index), (accumulator) => !accumulator);
283
311
  }
284
312
  throw new TypeError("Predicate must be a function.");
285
313
  };
286
314
  ;
287
- export let useGroup = (classifier) => {
315
+ export let useSynchronousGroup = (classifier) => {
288
316
  if (isFunction(classifier)) {
289
- return Collector.full(() => new Map(), (accumulator, element, index) => {
317
+ return SynchronousCollector.full(() => new Map(), (accumulator, element, index) => {
290
318
  let key = classifier(element, index);
291
319
  let group = accumulator.get(key) || [];
292
320
  group.push(element);
@@ -296,9 +324,9 @@ export let useGroup = (classifier) => {
296
324
  }
297
325
  throw new TypeError("Classifier must be a function.");
298
326
  };
299
- export let useGroupBy = (keyExtractor, valueExtractor = (element) => element) => {
327
+ export let useSynchronousGroupBy = (keyExtractor, valueExtractor = (element) => element) => {
300
328
  if (isFunction(keyExtractor) && isFunction(valueExtractor)) {
301
- return Collector.full(() => new Map(), (accumulator, element, index) => {
329
+ return SynchronousCollector.full(() => new Map(), (accumulator, element, index) => {
302
330
  let key = keyExtractor(element, index);
303
331
  let group = accumulator.get(key) || [];
304
332
  group.push(valueExtractor(element, index));
@@ -309,35 +337,35 @@ export let useGroupBy = (keyExtractor, valueExtractor = (element) => element) =>
309
337
  throw new TypeError("Key extractor and value extractor must be functions.");
310
338
  };
311
339
  ;
312
- export let useJoin = (argument1, argument2, argument3) => {
340
+ export let useSynchronousJoin = (argument1, argument2, argument3) => {
313
341
  if (invalidate(argument1) && invalidate(argument2) && invalidate(argument3)) {
314
- return Collector.full(() => "[", (text, element) => text + element + ",", (text) => text.substring(0, text.length - 1) + "]");
342
+ return SynchronousCollector.full(() => "[", (text, element) => text + element + ",", (text) => text.substring(0, text.length - 1) + "]");
315
343
  }
316
344
  if (isString(argument1) && invalidate(argument2) && invalidate(argument3)) {
317
345
  let delimiter = argument1;
318
- return Collector.full(() => "[", (text, element) => text + element + delimiter, (text) => text.substring(0, text.length - delimiter.length) + "]");
346
+ return SynchronousCollector.full(() => "[", (text, element) => text + element + delimiter, (text) => text.substring(0, text.length - delimiter.length) + "]");
319
347
  }
320
348
  if (isString(argument1) && isFunction(argument2) && isString(argument3)) {
321
349
  let prefix = argument1;
322
350
  let accumulator = argument2;
323
351
  let suffix = argument3;
324
- return Collector.full(() => prefix, accumulator, (text) => text + suffix);
352
+ return SynchronousCollector.full(() => prefix, accumulator, (text) => text + suffix);
325
353
  }
326
354
  if (isString(argument1) && isString(argument2) && isString(argument3)) {
327
355
  let prefix = argument1;
328
356
  let delimiter = argument2;
329
357
  let suffix = argument3;
330
- return Collector.full(() => prefix, (text, element) => text + element + delimiter, (text) => text + suffix);
358
+ return SynchronousCollector.full(() => prefix, (text, element) => text + element + delimiter, (text) => text + suffix);
331
359
  }
332
360
  throw new TypeError("Invalid arguments.");
333
361
  };
334
362
  ;
335
- export let useLog = (argument1, argument2, argument3) => {
363
+ export let useSynchronousLog = (argument1, argument2, argument3) => {
336
364
  if (isString(argument1) && isFunction(argument2) && isString(argument3)) {
337
365
  let prefix = argument1;
338
366
  let accumulator = argument2;
339
367
  let suffix = argument3;
340
- return Collector.full(() => prefix, accumulator, (text) => {
368
+ return SynchronousCollector.full(() => prefix, accumulator, (text) => {
341
369
  let result = text + suffix;
342
370
  console.log(result);
343
371
  return result;
@@ -347,15 +375,14 @@ export let useLog = (argument1, argument2, argument3) => {
347
375
  let prefix = "[";
348
376
  let accumulator = argument2;
349
377
  let suffix = "]";
350
- return Collector.full(() => prefix, accumulator, (text) => {
378
+ return SynchronousCollector.full(() => prefix, accumulator, (text) => {
351
379
  let result = text + suffix;
352
380
  console.log(result);
353
381
  return result;
354
382
  });
355
383
  }
356
384
  else {
357
- return Collector.full(() => "[", (accumulator, element) => {
358
- console.log(element);
385
+ return SynchronousCollector.full(() => "[", (accumulator, element) => {
359
386
  if (isString(accumulator) && isString(element)) {
360
387
  return accumulator + element + ",";
361
388
  }
@@ -367,10 +394,10 @@ export let useLog = (argument1, argument2, argument3) => {
367
394
  });
368
395
  }
369
396
  };
370
- export let usePartition = (count) => {
397
+ export let useSynchronousPartition = (count) => {
371
398
  if (isBigInt(count)) {
372
399
  let limited = count > 1n ? count : 1n;
373
- return Collector.full(() => {
400
+ return SynchronousCollector.full(() => {
374
401
  return [];
375
402
  }, (array, element) => {
376
403
  let index = limited % BigInt(array.length);
@@ -386,9 +413,9 @@ export let usePartition = (count) => {
386
413
  throw new TypeError("Count must be a BigInt.");
387
414
  };
388
415
  ;
389
- export let usePartitionBy = (classifier) => {
416
+ export let useSynchronousPartitionBy = (classifier) => {
390
417
  if (isFunction(classifier)) {
391
- return Collector.full(() => {
418
+ return SynchronousCollector.full(() => {
392
419
  return [];
393
420
  }, (array, element, index) => {
394
421
  let resolved = classifier(element, index);
@@ -404,44 +431,41 @@ export let usePartitionBy = (classifier) => {
404
431
  throw new TypeError("Classifier must be a function.");
405
432
  };
406
433
  ;
407
- export let useReduce = (argument1, argument2, argument3) => {
434
+ export let useSynchronousReduce = (argument1, argument2, argument3) => {
408
435
  if (isFunction(argument1) && invalidate(argument2) && invalidate(argument3)) {
409
436
  let accumulator = argument1;
410
- return Collector.full(() => Optional.ofNullable(), (result, element, index) => {
411
- if (result.isEmpty()) {
412
- return Optional.of(element);
413
- }
414
- else {
415
- let current = result.get();
416
- return Optional.of(accumulator(current, element, index));
437
+ return SynchronousCollector.full(() => Optional.empty(), (result, element, index) => {
438
+ if (validate(result) && result.isPresent()) {
439
+ return result.map((previous) => accumulator(previous, element, index));
417
440
  }
441
+ return result;
418
442
  }, (result) => result);
419
443
  }
420
444
  else if (validate(argument1) && isFunction(argument2) && invalidate(argument3)) {
421
445
  let identity = argument1;
422
446
  let accumulator = argument2;
423
- return Collector.full(() => identity, accumulator, (result) => result);
447
+ return SynchronousCollector.full(() => identity, accumulator, (result) => result);
424
448
  }
425
449
  else if (validate(argument1) && isFunction(argument2) && isFunction(argument3)) {
426
450
  let identity = argument1;
427
451
  let accumulator = argument2;
428
452
  let finisher = argument3;
429
- return Collector.full(() => identity, accumulator, finisher);
453
+ return SynchronousCollector.full(() => identity, accumulator, finisher);
430
454
  }
431
455
  else {
432
456
  throw new TypeError("Invalid arguments.");
433
457
  }
434
458
  };
435
- export let useToArray = () => {
436
- return Collector.full(() => [], (array, element) => {
459
+ export let useSynchronousToArray = () => {
460
+ return SynchronousCollector.full(() => [], (array, element) => {
437
461
  array.push(element);
438
462
  return array;
439
463
  }, (array) => array);
440
464
  };
441
465
  ;
442
- export let useToMap = (keyExtractor, valueExtractor = (element) => element) => {
466
+ export let useSynchronousToMap = (keyExtractor, valueExtractor = (element) => element) => {
443
467
  if (isFunction(keyExtractor) && isFunction(valueExtractor)) {
444
- return Collector.full(() => new Map(), (map, element, index) => {
468
+ return SynchronousCollector.full(() => new Map(), (map, element, index) => {
445
469
  let key = keyExtractor(element, index);
446
470
  let value = valueExtractor(element, index);
447
471
  map.set(key, value);
@@ -450,19 +474,19 @@ export let useToMap = (keyExtractor, valueExtractor = (element) => element) => {
450
474
  }
451
475
  throw new TypeError("Key extractor and value extractor must be functions.");
452
476
  };
453
- export let useToSet = () => {
454
- return Collector.full(() => new Set(), (set, element) => {
477
+ export let useSynchronousToSet = () => {
478
+ return SynchronousCollector.full(() => new Set(), (set, element) => {
455
479
  set.add(element);
456
480
  return set;
457
481
  }, (set) => set);
458
482
  };
459
483
  ;
460
- export let useWrite = (argument1, argument2) => {
484
+ export let useSynchronousWrite = (argument1, argument2) => {
461
485
  if (isObject(argument1)) {
462
486
  if (isFunction(argument2)) {
463
487
  let stream = argument1;
464
488
  let accumulator = argument2;
465
- return Collector.full(() => Promise.resolve(stream), (promise, element, index) => {
489
+ return SynchronousCollector.full(() => Promise.resolve(stream), (promise, element, index) => {
466
490
  return new Promise((resolve, reject) => {
467
491
  promise.then((stream) => {
468
492
  try {
@@ -477,7 +501,7 @@ export let useWrite = (argument1, argument2) => {
477
501
  }
478
502
  else {
479
503
  let stream = argument1;
480
- return Collector.full(() => Promise.resolve(stream), (promise, element) => {
504
+ return SynchronousCollector.full(() => Promise.resolve(stream), (promise, element) => {
481
505
  return new Promise((resolve, reject) => {
482
506
  promise.then((stream) => {
483
507
  try {
@@ -496,23 +520,23 @@ export let useWrite = (argument1, argument2) => {
496
520
  throw new TypeError("Invalid arguments.");
497
521
  };
498
522
  ;
499
- export let useNumericSummate = (mapper = useToNumber) => {
500
- return Collector.full(() => 0, (accumulator, element) => {
523
+ export let useSynchronousNumericSummate = (mapper = useToNumber) => {
524
+ return SynchronousCollector.full(() => 0, (accumulator, element) => {
501
525
  let resolved = isNumber(element) ? element : mapper(element);
502
526
  return accumulator + (isNumber(resolved) ? resolved : 0);
503
527
  }, (result) => result);
504
528
  };
505
529
  ;
506
- export let useBigIntSummate = (mapper = useToBigInt) => {
507
- return Collector.full(() => 0n, (accumulator, element) => {
530
+ export let useSynchronousBigIntSummate = (mapper = useToBigInt) => {
531
+ return SynchronousCollector.full(() => 0n, (accumulator, element) => {
508
532
  let resolved = isBigInt(element) ? element : mapper(element);
509
533
  return accumulator + (isBigInt(resolved) ? resolved : 0n);
510
534
  }, (result) => result);
511
535
  };
512
536
  ;
513
537
  ;
514
- export let useNumericAverage = (mapper = useToNumber) => {
515
- return Collector.full(() => {
538
+ export let useSynchronousNumericAverage = (mapper = useToNumber) => {
539
+ return SynchronousCollector.full(() => {
516
540
  return {
517
541
  summate: 0,
518
542
  count: 0
@@ -532,8 +556,8 @@ export let useNumericAverage = (mapper = useToNumber) => {
532
556
  };
533
557
  ;
534
558
  ;
535
- export let useBigIntAverage = (mapper = useToBigInt) => {
536
- return Collector.full(() => {
559
+ export let useSynchronousBigIntAverage = (mapper = useToBigInt) => {
560
+ return SynchronousCollector.full(() => {
537
561
  return {
538
562
  summate: 0n,
539
563
  count: 0n
@@ -551,16 +575,16 @@ export let useBigIntAverage = (mapper = useToBigInt) => {
551
575
  return result.summate / result.count;
552
576
  });
553
577
  };
554
- export let useFrequency = () => {
555
- return Collector.full(() => new Map(), (map, element) => {
578
+ export let useSynchronousFrequency = () => {
579
+ return SynchronousCollector.full(() => new Map(), (map, element) => {
556
580
  let count = map.get(element) || 0n;
557
581
  map.set(element, count + 1n);
558
582
  return map;
559
583
  }, (map) => map);
560
584
  };
561
585
  ;
562
- export let useNumericMode = (mapper = useToNumber) => {
563
- return Collector.full(() => new Map(), (map, element) => {
586
+ export let useSynchronousNumericMode = (mapper = useToNumber) => {
587
+ return SynchronousCollector.full(() => new Map(), (map, element) => {
564
588
  let resolved = isNumber(element) ? element : mapper(element);
565
589
  let count = map.get(resolved) || 0n;
566
590
  map.set(resolved, count + 1n);
@@ -578,8 +602,8 @@ export let useNumericMode = (mapper = useToNumber) => {
578
602
  });
579
603
  };
580
604
  ;
581
- export let useBigIntMode = (mapper = useToBigInt) => {
582
- return Collector.full(() => new Map(), (map, element) => {
605
+ export let useSynchronousBigIntMode = (mapper = useToBigInt) => {
606
+ return SynchronousCollector.full(() => new Map(), (map, element) => {
583
607
  let resolved = isBigInt(element) ? element : mapper(element);
584
608
  let count = map.get(resolved) || 0n;
585
609
  map.set(resolved, count + 1n);
@@ -598,8 +622,8 @@ export let useBigIntMode = (mapper = useToBigInt) => {
598
622
  };
599
623
  ;
600
624
  ;
601
- export let useNumericVariance = (mapper = useToNumber) => {
602
- return Collector.full(() => {
625
+ export let useSynchronousNumericVariance = (mapper = useToNumber) => {
626
+ return SynchronousCollector.full(() => {
603
627
  return {
604
628
  summate: 0,
605
629
  summateOfSquares: 0,
@@ -623,8 +647,8 @@ export let useNumericVariance = (mapper = useToNumber) => {
623
647
  };
624
648
  ;
625
649
  ;
626
- export let useBigIntVariance = (mapper = useToBigInt) => {
627
- return Collector.full(() => {
650
+ export let useSynchronousBigIntVariance = (mapper = useToBigInt) => {
651
+ return SynchronousCollector.full(() => {
628
652
  return {
629
653
  summate: 0n,
630
654
  summateOfSquares: 0n,
@@ -648,8 +672,8 @@ export let useBigIntVariance = (mapper = useToBigInt) => {
648
672
  };
649
673
  ;
650
674
  ;
651
- export let useNumericStandardDeviation = (mapper = useToNumber) => {
652
- return Collector.full(() => {
675
+ export let useSynchronousNumericStandardDeviation = (mapper = useToNumber) => {
676
+ return SynchronousCollector.full(() => {
653
677
  return {
654
678
  summate: 0,
655
679
  summateOfSquares: 0,
@@ -674,8 +698,8 @@ export let useNumericStandardDeviation = (mapper = useToNumber) => {
674
698
  };
675
699
  ;
676
700
  ;
677
- export let useBigIntStandardDeviation = (mapper = useToBigInt) => {
678
- return Collector.full(() => {
701
+ export let useSynchronousBigIntStandardDeviation = (mapper = useToBigInt) => {
702
+ return SynchronousCollector.full(() => {
679
703
  return {
680
704
  summate: 0n,
681
705
  summateOfSquares: 0n,
@@ -699,8 +723,8 @@ export let useBigIntStandardDeviation = (mapper = useToBigInt) => {
699
723
  });
700
724
  };
701
725
  ;
702
- export let useNumericMedian = (mapper = useToNumber) => {
703
- return Collector.full(() => [], (array, element) => {
726
+ export let useSynchronousNumericMedian = (mapper = useToNumber) => {
727
+ return SynchronousCollector.full(() => [], (array, element) => {
704
728
  let resolved = isNumber(element) ? element : mapper(element);
705
729
  array.push(resolved);
706
730
  array.sort((a, b) => a - b);
@@ -718,8 +742,8 @@ export let useNumericMedian = (mapper = useToNumber) => {
718
742
  });
719
743
  };
720
744
  ;
721
- export let useBigIntMedian = (mapper = useToBigInt) => {
722
- return Collector.full(() => [], (array, element) => {
745
+ export let useSynchronousBigIntMedian = (mapper = useToBigInt) => {
746
+ return SynchronousCollector.full(() => [], (array, element) => {
723
747
  let resolved = isBigInt(element) ? element : mapper(element);
724
748
  array.push(resolved);
725
749
  array.sort((a, b) => Number(a - b));
@@ -736,8 +760,8 @@ export let useBigIntMedian = (mapper = useToBigInt) => {
736
760
  }
737
761
  });
738
762
  };
739
- export let useToGeneratorFunction = () => {
740
- return Collector.full(() => [], (array, element) => {
763
+ export let useSynchronousToGeneratorFunction = () => {
764
+ return SynchronousCollector.full(() => [], (array, element) => {
741
765
  array.push(element);
742
766
  return array;
743
767
  }, (array) => {
@@ -748,8 +772,8 @@ export let useToGeneratorFunction = () => {
748
772
  })();
749
773
  });
750
774
  };
751
- export let useToAsyncGeneratorFunction = () => {
752
- return Collector.full(() => [], (array, element) => {
775
+ export let useSynchronousToAsyncGeneratorFunction = () => {
776
+ return SynchronousCollector.full(() => [], (array, element) => {
753
777
  array.push(element);
754
778
  return array;
755
779
  }, (array) => {