semantic-typescript 0.5.0 → 0.6.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.
- package/dist/asynchronous/collector.d.ts +231 -0
- package/dist/asynchronous/collector.js +800 -0
- package/dist/asynchronous/semantic.d.ts +257 -0
- package/dist/asynchronous/semantic.js +1853 -0
- package/dist/factory.d.ts +110 -32
- package/dist/factory.js +582 -189
- package/dist/guard.d.ts +24 -27
- package/dist/guard.js +37 -43
- package/dist/hook.d.ts +11 -7
- package/dist/hook.js +74 -21
- package/dist/index.d.ts +2 -3
- package/dist/index.js +2 -3
- package/dist/optional.d.ts +5 -5
- package/dist/optional.js +14 -10
- package/dist/symbol.d.ts +19 -23
- package/dist/symbol.js +19 -23
- package/dist/synchronous/collector.d.ts +232 -0
- package/dist/{collector.js → synchronous/collector.js} +160 -170
- package/dist/{collectable.d.ts → synchronous/semantic.d.ts} +114 -71
- package/dist/{collectable.js → synchronous/semantic.js} +761 -294
- package/dist/utility.d.ts +8 -2
- package/dist/utility.js +1 -0
- package/package.json +1 -1
- package/readme.cn.md +158 -697
- package/readme.de.md +163 -432
- package/readme.es.md +163 -433
- package/readme.fr.md +162 -444
- package/readme.jp.md +162 -442
- package/readme.kr.md +161 -430
- package/readme.md +157 -799
- package/readme.ru.md +161 -426
- package/readme.tw.md +161 -436
- package/dist/collector.d.ts +0 -245
- package/dist/map.d.ts +0 -76
- package/dist/map.js +0 -253
- package/dist/node.d.ts +0 -182
- package/dist/node.js +0 -918
- package/dist/semantic.d.ts +0 -52
- package/dist/semantic.js +0 -504
- package/dist/set.d.ts +0 -19
- package/dist/set.js +0 -65
- package/dist/statistics.d.ts +0 -97
- package/dist/statistics.js +0 -483
- package/dist/tree.d.ts +0 -82
- package/dist/tree.js +0 -257
- package/dist/window.d.ts +0 -12
- package/dist/window.js +0 -72
|
@@ -0,0 +1,1853 @@
|
|
|
1
|
+
import { useAsynchronousAnyMatch, useAsynchronousAllMatch, useAsynchronousCollect, useAsynchronousCount, useAsynchronousError, useAsynchronousFindAny, useAsynchronousFindAt, useAsynchronousFindFirst, useAsynchronousFindLast, useAsynchronousFindMaximum, useAsynchronousFindMinimum, useAsynchronousForEach, useAsynchronousGroup, useAsynchronousGroupBy, useAsynchronousJoin, useAsynchronousLog, useAsynchronousNoneMatch, useAsynchronousPartition, useAsynchronousPartitionBy, useAsynchronousReduce, useAsynchronousToArray, useAsynchronousToMap, useAsynchronousToSet, useAsynchronousWrite, useAsynchronousFrequency, useAsynchronousBigIntAverage, useAsynchronousBigIntMedian, useAsynchronousBigIntMode, useAsynchronousBigIntSummate, useAsynchronousBigIntVariance, useAsynchronousNumericAverage, useAsynchronousNumericMedian, useAsynchronousNumericMode, useAsynchronousNumericStandardDeviation, useAsynchronousNumericSummate, useAsynchronousNumericVariance } from "./collector";
|
|
2
|
+
import { isFunction, isAsynchronousSemantic, isIterable, isNumber, isBigInt, isObject, isString, isAsynchronousCollectable, isAsyncIterable, isAsynchronousCollector } from "../guard";
|
|
3
|
+
import { useHash } from "../hash";
|
|
4
|
+
import { useCompare, useToBigInt, useToNumber } from "../hook";
|
|
5
|
+
import { AsynchronousOrderedCollectableSymbol, AsynchronousBigIntStatisticsSymbol, AsynchronousCollectableSymbol, AsynchronousNumericStatisticsSymbol, AsynchronousSemanticSymbol, AsynchronousWindowCollectableSymbol, AsynchronousUnorderedCollectableSymbol, AsynchronousStatisticsSymbol } from "../symbol";
|
|
6
|
+
import { invalidate, validate } from "../utility";
|
|
7
|
+
export class AsynchronousSemantic {
|
|
8
|
+
generator;
|
|
9
|
+
AsynchronousSemantic = AsynchronousSemanticSymbol;
|
|
10
|
+
[Symbol.toStringTag] = "AsynchronousSemantic";
|
|
11
|
+
constructor(generator) {
|
|
12
|
+
if (isFunction(generator)) {
|
|
13
|
+
this.generator = generator;
|
|
14
|
+
Object.defineProperties(this, {
|
|
15
|
+
"AsynchronousSemantic": {
|
|
16
|
+
value: AsynchronousSemanticSymbol,
|
|
17
|
+
writable: false,
|
|
18
|
+
enumerable: false,
|
|
19
|
+
configurable: false
|
|
20
|
+
},
|
|
21
|
+
"generator": {
|
|
22
|
+
value: generator,
|
|
23
|
+
writable: false,
|
|
24
|
+
enumerable: false,
|
|
25
|
+
configurable: false
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
throw new TypeError("Invalid arguments.");
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
concat(argument) {
|
|
34
|
+
if (isAsynchronousSemantic(argument)) {
|
|
35
|
+
let other = argument;
|
|
36
|
+
let generator = Reflect.get(other, "generator");
|
|
37
|
+
return new AsynchronousSemantic(async (accept, interrupt) => {
|
|
38
|
+
let count = 0n;
|
|
39
|
+
return new Promise((resolve, reject) => {
|
|
40
|
+
this.generator((element) => {
|
|
41
|
+
accept(element, count);
|
|
42
|
+
count++;
|
|
43
|
+
}, interrupt).then(() => {
|
|
44
|
+
generator((element) => {
|
|
45
|
+
accept(element, count);
|
|
46
|
+
count++;
|
|
47
|
+
}, interrupt);
|
|
48
|
+
}).then(resolve, reject);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
if (isAsyncIterable(argument)) {
|
|
53
|
+
let other = argument;
|
|
54
|
+
return new AsynchronousSemantic(async (accept, interrupt) => {
|
|
55
|
+
return new Promise((resolve, reject) => {
|
|
56
|
+
try {
|
|
57
|
+
let count = 0n;
|
|
58
|
+
this.generator((element, index) => {
|
|
59
|
+
accept(element, index);
|
|
60
|
+
count++;
|
|
61
|
+
}, interrupt).then(async () => {
|
|
62
|
+
for await (let element of other) {
|
|
63
|
+
accept(element, count);
|
|
64
|
+
count++;
|
|
65
|
+
}
|
|
66
|
+
resolve();
|
|
67
|
+
}).catch(reject);
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
reject(error);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
throw new TypeError("Invalid arguments.");
|
|
76
|
+
}
|
|
77
|
+
distinct(argument1) {
|
|
78
|
+
let keyExtractor = validate(argument1) ? argument1 : (element) => element;
|
|
79
|
+
return new AsynchronousSemantic(async (accept, interrupt) => {
|
|
80
|
+
return new Promise((resolve, reject) => {
|
|
81
|
+
try {
|
|
82
|
+
let set = new Set();
|
|
83
|
+
this.generator((element, index) => {
|
|
84
|
+
let key = keyExtractor(element, index);
|
|
85
|
+
if (!set.has(key)) {
|
|
86
|
+
set.add(key);
|
|
87
|
+
accept(element, index);
|
|
88
|
+
}
|
|
89
|
+
}, interrupt).then(resolve).catch(reject);
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
reject(error);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
dropWhile(predicate) {
|
|
98
|
+
if (isFunction(predicate)) {
|
|
99
|
+
return new AsynchronousSemantic(async (accept, interrupt) => {
|
|
100
|
+
return new Promise((resolve, reject) => {
|
|
101
|
+
try {
|
|
102
|
+
let count = -1n;
|
|
103
|
+
this.generator((element, index) => {
|
|
104
|
+
if (count === -1n) {
|
|
105
|
+
if (!predicate(element, index)) {
|
|
106
|
+
count++;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
accept(element, count);
|
|
111
|
+
count++;
|
|
112
|
+
}
|
|
113
|
+
}, interrupt).then(resolve).catch(reject);
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
reject(error);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
throw new TypeError("Invalid arguments.");
|
|
122
|
+
}
|
|
123
|
+
filter(predicate) {
|
|
124
|
+
if (isFunction(predicate)) {
|
|
125
|
+
return new AsynchronousSemantic(async (accept, interrupt) => {
|
|
126
|
+
return new Promise((resolve, reject) => {
|
|
127
|
+
try {
|
|
128
|
+
this.generator((element, index) => {
|
|
129
|
+
if (predicate(element, index)) {
|
|
130
|
+
accept(element, index);
|
|
131
|
+
}
|
|
132
|
+
}, interrupt).then(resolve).catch(reject);
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
reject(error);
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
throw new TypeError("Invalid arguments.");
|
|
141
|
+
}
|
|
142
|
+
flat(mapper) {
|
|
143
|
+
if (isFunction(mapper)) {
|
|
144
|
+
return new AsynchronousSemantic(async (accept, interrupt) => {
|
|
145
|
+
return new Promise((resolve, reject) => {
|
|
146
|
+
try {
|
|
147
|
+
let count = 0n;
|
|
148
|
+
let stop = false;
|
|
149
|
+
this.generator((element, index) => {
|
|
150
|
+
let result = mapper(element, index);
|
|
151
|
+
if (isIterable(result)) {
|
|
152
|
+
for (let subElement of result) {
|
|
153
|
+
accept(subElement, count);
|
|
154
|
+
stop = stop || interrupt(subElement, count);
|
|
155
|
+
count++;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
else if (isAsynchronousSemantic(result)) {
|
|
159
|
+
result.generator((subElement) => {
|
|
160
|
+
accept(subElement, count);
|
|
161
|
+
stop = stop || interrupt(subElement, count);
|
|
162
|
+
count++;
|
|
163
|
+
}, (element) => interrupt(element, count) || stop);
|
|
164
|
+
}
|
|
165
|
+
}, (element) => interrupt(element, count) || stop).then(resolve, reject);
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
reject(error);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
throw new TypeError("Invalid arguments.");
|
|
174
|
+
}
|
|
175
|
+
flatMap(mapper) {
|
|
176
|
+
if (isFunction(mapper)) {
|
|
177
|
+
return new AsynchronousSemantic(async (accept, interrupt) => {
|
|
178
|
+
return new Promise((resolve, reject) => {
|
|
179
|
+
try {
|
|
180
|
+
let count = 0n;
|
|
181
|
+
let stop = false;
|
|
182
|
+
this.generator((element, index) => {
|
|
183
|
+
let result = mapper(element, index);
|
|
184
|
+
if (isIterable(result)) {
|
|
185
|
+
for (let subElement of result) {
|
|
186
|
+
accept(subElement, count);
|
|
187
|
+
stop = stop || interrupt(subElement, count);
|
|
188
|
+
count++;
|
|
189
|
+
}
|
|
190
|
+
resolve();
|
|
191
|
+
}
|
|
192
|
+
else if (isAsynchronousSemantic(result)) {
|
|
193
|
+
result.generator((subElement) => {
|
|
194
|
+
accept(subElement, count);
|
|
195
|
+
stop = stop || interrupt(subElement, count);
|
|
196
|
+
count++;
|
|
197
|
+
}, (element) => interrupt(element, count) || stop).then(resolve, reject);
|
|
198
|
+
}
|
|
199
|
+
}, () => stop);
|
|
200
|
+
}
|
|
201
|
+
catch (error) {
|
|
202
|
+
reject(error);
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
throw new TypeError("Invalid arguments.");
|
|
208
|
+
}
|
|
209
|
+
limit(argument) {
|
|
210
|
+
if (isNumber(argument)) {
|
|
211
|
+
let limit = BigInt(argument);
|
|
212
|
+
return new AsynchronousSemantic(async (accept, interrupt) => {
|
|
213
|
+
return new Promise((resolve, reject) => {
|
|
214
|
+
try {
|
|
215
|
+
let count = 0n;
|
|
216
|
+
this.generator((element) => {
|
|
217
|
+
if (count < limit) {
|
|
218
|
+
accept(element, count);
|
|
219
|
+
count++;
|
|
220
|
+
}
|
|
221
|
+
}, (element, index) => interrupt(element, index) || count >= limit).then(resolve, reject);
|
|
222
|
+
}
|
|
223
|
+
catch (error) {
|
|
224
|
+
reject(error);
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
if (isBigInt(argument)) {
|
|
230
|
+
let limit = argument;
|
|
231
|
+
return new AsynchronousSemantic(async (accept, interrupt) => {
|
|
232
|
+
return new Promise((resolve, reject) => {
|
|
233
|
+
try {
|
|
234
|
+
let count = 0n;
|
|
235
|
+
this.generator((element) => {
|
|
236
|
+
if (count < limit) {
|
|
237
|
+
accept(element, count);
|
|
238
|
+
count++;
|
|
239
|
+
}
|
|
240
|
+
}, (element, index) => interrupt(element, index) || count >= limit).then(resolve, reject);
|
|
241
|
+
}
|
|
242
|
+
catch (error) {
|
|
243
|
+
reject(error);
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
throw new TypeError("Invalid arguments.");
|
|
249
|
+
}
|
|
250
|
+
map(mapper) {
|
|
251
|
+
if (isFunction(mapper)) {
|
|
252
|
+
return new AsynchronousSemantic(async (accept, interrupt) => {
|
|
253
|
+
return new Promise((resolve, reject) => {
|
|
254
|
+
try {
|
|
255
|
+
let stop = false;
|
|
256
|
+
this.generator((element, index) => {
|
|
257
|
+
let resolved = mapper(element, index);
|
|
258
|
+
accept(resolved, index);
|
|
259
|
+
stop = stop || interrupt(resolved, index);
|
|
260
|
+
}, () => stop).then(resolve, reject);
|
|
261
|
+
}
|
|
262
|
+
catch (error) {
|
|
263
|
+
reject(error);
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
throw new TypeError("Invalid arguments.");
|
|
269
|
+
}
|
|
270
|
+
peek(consumer) {
|
|
271
|
+
if (isFunction(consumer)) {
|
|
272
|
+
return new AsynchronousSemantic(async (accept, interrupt) => {
|
|
273
|
+
return new Promise((resolve, reject) => {
|
|
274
|
+
try {
|
|
275
|
+
this.generator((element, index) => {
|
|
276
|
+
accept(element, index);
|
|
277
|
+
consumer(element, index);
|
|
278
|
+
}, interrupt).then(resolve, reject);
|
|
279
|
+
}
|
|
280
|
+
catch (error) {
|
|
281
|
+
reject(error);
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
throw new TypeError("Invalid arguments.");
|
|
287
|
+
}
|
|
288
|
+
redirect(redirector) {
|
|
289
|
+
if (isFunction(redirector)) {
|
|
290
|
+
return new AsynchronousSemantic(async (accept, interrupt) => {
|
|
291
|
+
return new Promise((resolve, reject) => {
|
|
292
|
+
try {
|
|
293
|
+
this.generator((element, index) => {
|
|
294
|
+
accept(element, redirector(element, index));
|
|
295
|
+
}, interrupt).then(resolve, reject);
|
|
296
|
+
}
|
|
297
|
+
catch (error) {
|
|
298
|
+
reject(error);
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
throw new TypeError("Invalid arguments.");
|
|
304
|
+
}
|
|
305
|
+
reverse() {
|
|
306
|
+
return new AsynchronousSemantic(async (accept, interrupt) => {
|
|
307
|
+
return new Promise((resolve, reject) => {
|
|
308
|
+
try {
|
|
309
|
+
this.generator((element, index) => {
|
|
310
|
+
accept(element, -index);
|
|
311
|
+
}, interrupt).then(resolve, reject);
|
|
312
|
+
}
|
|
313
|
+
catch (error) {
|
|
314
|
+
reject(error);
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
shuffle(mapper) {
|
|
320
|
+
if (isFunction(mapper)) {
|
|
321
|
+
return new AsynchronousSemantic(async (accept, interrupt) => {
|
|
322
|
+
return new Promise((resolve, reject) => {
|
|
323
|
+
try {
|
|
324
|
+
this.generator((element, index) => {
|
|
325
|
+
accept(element, mapper(element, index));
|
|
326
|
+
}, interrupt).then(resolve, reject);
|
|
327
|
+
}
|
|
328
|
+
catch (error) {
|
|
329
|
+
reject(error);
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
return new AsynchronousSemantic(async (accept, interrupt) => {
|
|
335
|
+
return new Promise((resolve, reject) => {
|
|
336
|
+
try {
|
|
337
|
+
this.generator((element, index) => {
|
|
338
|
+
accept(element, useHash(element, index));
|
|
339
|
+
}, interrupt).then(resolve, reject);
|
|
340
|
+
}
|
|
341
|
+
catch (error) {
|
|
342
|
+
reject(error);
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
skip(argument) {
|
|
348
|
+
if (isNumber(argument)) {
|
|
349
|
+
let n = argument;
|
|
350
|
+
return new AsynchronousSemantic(async (accept, interrupt) => {
|
|
351
|
+
return new Promise((resolve, reject) => {
|
|
352
|
+
try {
|
|
353
|
+
let count = 0n;
|
|
354
|
+
let limit = BigInt(n);
|
|
355
|
+
this.generator((element, index) => {
|
|
356
|
+
if (count < limit) {
|
|
357
|
+
count++;
|
|
358
|
+
}
|
|
359
|
+
else {
|
|
360
|
+
accept(element, index);
|
|
361
|
+
}
|
|
362
|
+
}, interrupt).then(resolve, reject);
|
|
363
|
+
}
|
|
364
|
+
catch (error) {
|
|
365
|
+
reject(error);
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
if (isBigInt(argument)) {
|
|
371
|
+
let n = argument;
|
|
372
|
+
return new AsynchronousSemantic(async (accept, interrupt) => {
|
|
373
|
+
return new Promise((resolve, reject) => {
|
|
374
|
+
try {
|
|
375
|
+
let count = 0n;
|
|
376
|
+
this.generator((element, index) => {
|
|
377
|
+
if (count < n) {
|
|
378
|
+
count++;
|
|
379
|
+
}
|
|
380
|
+
else {
|
|
381
|
+
accept(element, index);
|
|
382
|
+
}
|
|
383
|
+
}, interrupt).then(resolve, reject);
|
|
384
|
+
}
|
|
385
|
+
catch (error) {
|
|
386
|
+
reject(error);
|
|
387
|
+
}
|
|
388
|
+
});
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
throw new TypeError("Invalid arguments.");
|
|
392
|
+
}
|
|
393
|
+
source() {
|
|
394
|
+
return this.generator;
|
|
395
|
+
}
|
|
396
|
+
sub(start, end) {
|
|
397
|
+
if ((isNumber(start) && isNumber(end)) || (isBigInt(start) && isBigInt(end))) {
|
|
398
|
+
return new AsynchronousSemantic(async (accept, interrupt) => {
|
|
399
|
+
return new Promise((resolve, reject) => {
|
|
400
|
+
try {
|
|
401
|
+
let count = 0n;
|
|
402
|
+
let resolvedStart = useToBigInt(start);
|
|
403
|
+
let resolvedEnd = useToBigInt(end);
|
|
404
|
+
let minimum = resolvedStart < resolvedEnd ? resolvedStart : resolvedEnd;
|
|
405
|
+
let maximum = resolvedStart < resolvedEnd ? resolvedEnd : resolvedStart;
|
|
406
|
+
this.generator((element, index) => {
|
|
407
|
+
if (minimum <= count && count < maximum) {
|
|
408
|
+
accept(element, index);
|
|
409
|
+
count++;
|
|
410
|
+
}
|
|
411
|
+
}, (element, index) => count >= maximum || interrupt(element, index)).then(resolve, reject);
|
|
412
|
+
}
|
|
413
|
+
catch (error) {
|
|
414
|
+
reject(error);
|
|
415
|
+
}
|
|
416
|
+
});
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
throw new TypeError("Invalid arguments.");
|
|
420
|
+
}
|
|
421
|
+
takeWhile(predicate) {
|
|
422
|
+
return new AsynchronousSemantic(async (accept, interrupt) => {
|
|
423
|
+
return new Promise((resolve, reject) => {
|
|
424
|
+
try {
|
|
425
|
+
let stop = false;
|
|
426
|
+
this.generator((element, index) => {
|
|
427
|
+
if (predicate(element, index) && stop === false) {
|
|
428
|
+
accept(element, index);
|
|
429
|
+
}
|
|
430
|
+
else {
|
|
431
|
+
stop = true;
|
|
432
|
+
}
|
|
433
|
+
}, (element, index) => stop || interrupt(element, index)).then(resolve, reject);
|
|
434
|
+
}
|
|
435
|
+
catch (error) {
|
|
436
|
+
reject(error);
|
|
437
|
+
}
|
|
438
|
+
});
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
toAsynchronousCollectable(mapper) {
|
|
442
|
+
if (isFunction(mapper)) {
|
|
443
|
+
try {
|
|
444
|
+
let AsynchronousCollectable = mapper(this.generator);
|
|
445
|
+
if (isAsynchronousCollectable(AsynchronousCollectable)) {
|
|
446
|
+
return AsynchronousCollectable;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
catch (error) {
|
|
450
|
+
throw new Error("Uncaught error on toAsynchronousCollectable.");
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
try {
|
|
454
|
+
return new AsynchronousUnorderedCollectable(this.generator);
|
|
455
|
+
}
|
|
456
|
+
catch (error) {
|
|
457
|
+
throw new Error("Uncaught error on toAsynchronousCollectable.");
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
toBigintStatistics() {
|
|
461
|
+
try {
|
|
462
|
+
return new AsynchronousBigIntStatistics(this.generator);
|
|
463
|
+
}
|
|
464
|
+
catch (error) {
|
|
465
|
+
throw new Error("Uncaught error on toBigintStatistics.");
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
toNumericStatistics() {
|
|
469
|
+
try {
|
|
470
|
+
return new AsynchronousNumericStatistics(this.generator);
|
|
471
|
+
}
|
|
472
|
+
catch (error) {
|
|
473
|
+
throw new Error("Uncaught error on toNumericStatistics.");
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
toOrdered() {
|
|
477
|
+
try {
|
|
478
|
+
return new AsynchronousOrderedCollectable(this.generator);
|
|
479
|
+
}
|
|
480
|
+
catch (error) {
|
|
481
|
+
throw new Error("Uncaught error on toOrdered.");
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
toUnordered() {
|
|
485
|
+
try {
|
|
486
|
+
return new AsynchronousUnorderedCollectable(this.generator);
|
|
487
|
+
}
|
|
488
|
+
catch (error) {
|
|
489
|
+
throw new Error(String(error));
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
toWindow() {
|
|
493
|
+
try {
|
|
494
|
+
return new AsynchronousWindowCollectable(this.generator);
|
|
495
|
+
}
|
|
496
|
+
catch (error) {
|
|
497
|
+
throw new Error("Uncaught error on toWindow.");
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
translate(argument1) {
|
|
501
|
+
if (isNumber(argument1)) {
|
|
502
|
+
let offset = argument1;
|
|
503
|
+
return new AsynchronousSemantic(async (accept, interrupt) => {
|
|
504
|
+
try {
|
|
505
|
+
this.generator((element, index) => {
|
|
506
|
+
accept(element, index + BigInt(offset));
|
|
507
|
+
}, interrupt);
|
|
508
|
+
}
|
|
509
|
+
catch (error) {
|
|
510
|
+
throw new Error("Uncaught error on translate.");
|
|
511
|
+
}
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
else if (isBigInt(argument1)) {
|
|
515
|
+
let offset = argument1;
|
|
516
|
+
return new AsynchronousSemantic(async (accept, interrupt) => {
|
|
517
|
+
try {
|
|
518
|
+
this.generator((element, index) => {
|
|
519
|
+
accept(element, index + offset);
|
|
520
|
+
}, interrupt);
|
|
521
|
+
}
|
|
522
|
+
catch (error) {
|
|
523
|
+
throw new Error("Uncaught error on translate.");
|
|
524
|
+
}
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
else if (isFunction(argument1)) {
|
|
528
|
+
let translator = argument1;
|
|
529
|
+
return new AsynchronousSemantic(async (accept, interrupt) => {
|
|
530
|
+
try {
|
|
531
|
+
this.generator((element, index) => {
|
|
532
|
+
accept(element, index + translator(element, index));
|
|
533
|
+
}, interrupt);
|
|
534
|
+
}
|
|
535
|
+
catch (error) {
|
|
536
|
+
throw new Error("Uncaught error on translate.");
|
|
537
|
+
}
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
throw new TypeError("Invalid arguments.");
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
;
|
|
544
|
+
export class AsynchronousCollectable {
|
|
545
|
+
AsynchronousCollectable = AsynchronousCollectableSymbol;
|
|
546
|
+
[Symbol.toStringTag] = "AsynchronousCollectable";
|
|
547
|
+
constructor() {
|
|
548
|
+
Object.defineProperty(this, "AsynchronousCollectable", {
|
|
549
|
+
value: AsynchronousCollectableSymbol,
|
|
550
|
+
enumerable: false,
|
|
551
|
+
writable: false,
|
|
552
|
+
configurable: false
|
|
553
|
+
});
|
|
554
|
+
}
|
|
555
|
+
async *[Symbol.asyncIterator]() {
|
|
556
|
+
for await (let element of await this.toArray()) {
|
|
557
|
+
yield element;
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
async anyMatch(predicate) {
|
|
561
|
+
if (isFunction(predicate)) {
|
|
562
|
+
try {
|
|
563
|
+
return await useAsynchronousAnyMatch(predicate).collect(this.source());
|
|
564
|
+
}
|
|
565
|
+
catch (error) {
|
|
566
|
+
throw new Error("Uncaught error on anyMatch.");
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
throw new TypeError("Predicate must be a function.");
|
|
570
|
+
}
|
|
571
|
+
async allMatch(predicate) {
|
|
572
|
+
return useAsynchronousAllMatch(predicate).collect(this.source());
|
|
573
|
+
}
|
|
574
|
+
async collect(argument1, argument2, argument3, argument4) {
|
|
575
|
+
try {
|
|
576
|
+
if (isAsynchronousCollector(argument1)) {
|
|
577
|
+
let collector = argument1;
|
|
578
|
+
return await collector.collect(this.source());
|
|
579
|
+
}
|
|
580
|
+
if (isFunction(argument1) && isFunction(argument2) && isFunction(argument3)) {
|
|
581
|
+
let identity = argument1;
|
|
582
|
+
let accumulator = argument2;
|
|
583
|
+
let finisher = argument3;
|
|
584
|
+
return await useAsynchronousCollect(identity, accumulator, finisher).collect(this.source());
|
|
585
|
+
}
|
|
586
|
+
if (isFunction(argument1) && isFunction(argument2) && isFunction(argument3) && isFunction(argument4)) {
|
|
587
|
+
let identity = argument1;
|
|
588
|
+
let interrupt = argument2;
|
|
589
|
+
let accumulator = argument3;
|
|
590
|
+
let finisher = argument4;
|
|
591
|
+
return await useAsynchronousCollect(identity, interrupt, accumulator, finisher).collect(this.source());
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
catch (error) {
|
|
595
|
+
throw new Error("Uncaught error on collect.");
|
|
596
|
+
}
|
|
597
|
+
throw new TypeError("Invalid arguments.");
|
|
598
|
+
}
|
|
599
|
+
async count() {
|
|
600
|
+
return await useAsynchronousCount().collect(this.source());
|
|
601
|
+
}
|
|
602
|
+
async error(argument1, argument2, argument3) {
|
|
603
|
+
if (invalidate(argument1) && invalidate(argument2) && invalidate(argument3)) {
|
|
604
|
+
try {
|
|
605
|
+
await useAsynchronousError().collect(this.source());
|
|
606
|
+
}
|
|
607
|
+
catch (error) {
|
|
608
|
+
throw new Error("Uncaught error on error.");
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
else if (isFunction(argument1) && invalidate(argument2) && invalidate(argument3)) {
|
|
612
|
+
try {
|
|
613
|
+
let accumulator = argument1;
|
|
614
|
+
await useAsynchronousError(accumulator).collect(this.source());
|
|
615
|
+
}
|
|
616
|
+
catch (error) {
|
|
617
|
+
throw new Error("Uncaught error on error.");
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
else if (isString(argument1) && isFunction(argument2) && isString(argument3)) {
|
|
621
|
+
try {
|
|
622
|
+
let prefix = argument1;
|
|
623
|
+
let accumulator = argument2;
|
|
624
|
+
let suffix = argument3;
|
|
625
|
+
await useAsynchronousError(prefix, accumulator, suffix).collect(this.source());
|
|
626
|
+
}
|
|
627
|
+
catch (error) {
|
|
628
|
+
throw new Error("Uncaught error on error.");
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
else {
|
|
632
|
+
throw new TypeError("Invalid arguments.");
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
async isEmpty() {
|
|
636
|
+
return await this.count() === 0n;
|
|
637
|
+
}
|
|
638
|
+
async findAny() {
|
|
639
|
+
try {
|
|
640
|
+
return await useAsynchronousFindAny().collect(this.source());
|
|
641
|
+
}
|
|
642
|
+
catch (error) {
|
|
643
|
+
throw new Error("Uncaught error on findAny.");
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
async findAt(index) {
|
|
647
|
+
if (isBigInt(index)) {
|
|
648
|
+
try {
|
|
649
|
+
return await useAsynchronousFindAt(index).collect(this.source());
|
|
650
|
+
}
|
|
651
|
+
catch (error) {
|
|
652
|
+
throw new Error("Uncaught error on findAt.");
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
else if (isNumber(index)) {
|
|
656
|
+
try {
|
|
657
|
+
return await useAsynchronousFindAt(index).collect(this.source());
|
|
658
|
+
}
|
|
659
|
+
catch (error) {
|
|
660
|
+
throw new Error("Uncaught error on findAt.");
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
throw new TypeError("Index must be a bigint.");
|
|
664
|
+
}
|
|
665
|
+
async findFirst() {
|
|
666
|
+
try {
|
|
667
|
+
return await useAsynchronousFindFirst().collect(this.source());
|
|
668
|
+
}
|
|
669
|
+
catch (error) {
|
|
670
|
+
throw new Error("Uncaught error on findFirst.");
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
async findLast() {
|
|
674
|
+
try {
|
|
675
|
+
return await useAsynchronousFindLast().collect(this.source());
|
|
676
|
+
}
|
|
677
|
+
catch (error) {
|
|
678
|
+
throw new Error("Uncaught error on findLast.");
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
async findMaximum(argument1) {
|
|
682
|
+
try {
|
|
683
|
+
let comparator = isFunction(argument1) ? argument1 : useCompare;
|
|
684
|
+
return await useAsynchronousFindMaximum(comparator).collect(this.source());
|
|
685
|
+
}
|
|
686
|
+
catch (error) {
|
|
687
|
+
throw new Error("Uncaught error on findMaximum.");
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
async findMinimum(argument1) {
|
|
691
|
+
try {
|
|
692
|
+
let comparator = isFunction(argument1) ? argument1 : useCompare;
|
|
693
|
+
return await useAsynchronousFindMinimum(comparator).collect(this.source());
|
|
694
|
+
}
|
|
695
|
+
catch (error) {
|
|
696
|
+
throw new Error("Uncaught error on findMinimum.");
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
async forEach(action) {
|
|
700
|
+
if (isFunction(action)) {
|
|
701
|
+
try {
|
|
702
|
+
await useAsynchronousForEach(action).collect(this);
|
|
703
|
+
}
|
|
704
|
+
catch (error) {
|
|
705
|
+
throw new Error("Uncaught error on forEach.");
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
else {
|
|
709
|
+
throw new TypeError("Action must be a function.");
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
async group(classifier) {
|
|
713
|
+
if (isFunction(classifier)) {
|
|
714
|
+
try {
|
|
715
|
+
return await useAsynchronousGroup(classifier).collect(this.source());
|
|
716
|
+
}
|
|
717
|
+
catch (error) {
|
|
718
|
+
throw new Error("Uncaught error on group.");
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
throw new TypeError("Classifier must be a function.");
|
|
722
|
+
}
|
|
723
|
+
async groupBy(keyExtractor, valueExtractor) {
|
|
724
|
+
if (isFunction(keyExtractor) && isFunction(valueExtractor)) {
|
|
725
|
+
try {
|
|
726
|
+
return await useAsynchronousGroupBy(keyExtractor, valueExtractor).collect(this.source());
|
|
727
|
+
}
|
|
728
|
+
catch (error) {
|
|
729
|
+
throw new Error("Uncaught error on groupBy.");
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
throw new TypeError("Key and value extractors must be functions.");
|
|
733
|
+
}
|
|
734
|
+
async join(argument1, argument2, argument3) {
|
|
735
|
+
if (invalidate(argument1) && invalidate(argument2) && invalidate(argument3)) {
|
|
736
|
+
try {
|
|
737
|
+
return await useAsynchronousJoin().collect(this.source());
|
|
738
|
+
}
|
|
739
|
+
catch (error) {
|
|
740
|
+
throw new Error("Uncaught error on join.");
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
else if (isString(argument1) && invalidate(argument2) && invalidate(argument3)) {
|
|
744
|
+
try {
|
|
745
|
+
let delimiter = argument1;
|
|
746
|
+
return await useAsynchronousJoin(delimiter).collect(this.source());
|
|
747
|
+
}
|
|
748
|
+
catch (error) {
|
|
749
|
+
throw new Error("Uncaught error on join.");
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
else if (isString(argument1) && isFunction(argument2) && isString(argument3)) {
|
|
753
|
+
try {
|
|
754
|
+
let prefix = argument1;
|
|
755
|
+
let accumulator = argument2;
|
|
756
|
+
let suffix = argument3;
|
|
757
|
+
return await useAsynchronousJoin(prefix, accumulator, suffix).collect(this.source());
|
|
758
|
+
}
|
|
759
|
+
catch (error) {
|
|
760
|
+
throw new Error("Uncaught error on join.");
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
else if (isString(argument1) && isString(argument2) && isString(argument3)) {
|
|
764
|
+
try {
|
|
765
|
+
let prefix = argument1;
|
|
766
|
+
let delimiter = argument2;
|
|
767
|
+
let suffix = argument3;
|
|
768
|
+
return await useAsynchronousJoin(prefix, delimiter, suffix).collect(this.source());
|
|
769
|
+
}
|
|
770
|
+
catch (error) {
|
|
771
|
+
throw new Error("Uncaught error on join.");
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
throw new TypeError("Invalid arguments.");
|
|
775
|
+
}
|
|
776
|
+
async log(argument1, argument2, argument3) {
|
|
777
|
+
if (isFunction(argument1) && invalidate(argument2) && invalidate(argument3)) {
|
|
778
|
+
try {
|
|
779
|
+
let accumulator = argument1;
|
|
780
|
+
await useAsynchronousLog(accumulator).collect(this.source());
|
|
781
|
+
}
|
|
782
|
+
catch (error) {
|
|
783
|
+
throw new Error("Uncaught error on log.");
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
else if (isString(argument1) && isFunction(argument2) && isString(argument3)) {
|
|
787
|
+
try {
|
|
788
|
+
let prefix = argument1;
|
|
789
|
+
let accumulator = argument2;
|
|
790
|
+
let suffix = argument3;
|
|
791
|
+
await useAsynchronousLog(prefix, accumulator, suffix).collect(this.source());
|
|
792
|
+
}
|
|
793
|
+
catch (error) {
|
|
794
|
+
throw new Error("Uncaught error on log.");
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
else {
|
|
798
|
+
try {
|
|
799
|
+
useAsynchronousLog().collect(this.source());
|
|
800
|
+
}
|
|
801
|
+
catch (error) {
|
|
802
|
+
throw new Error("Uncaught error on log.");
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
async nonMatch(predicate) {
|
|
807
|
+
if (isFunction(predicate)) {
|
|
808
|
+
try {
|
|
809
|
+
return await useAsynchronousNoneMatch(predicate).collect(this.source());
|
|
810
|
+
}
|
|
811
|
+
catch (error) {
|
|
812
|
+
throw new Error("Uncaught error on nonMatch.");
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
throw new TypeError("Predicate must be a function.");
|
|
816
|
+
}
|
|
817
|
+
async partition(count) {
|
|
818
|
+
if (isBigInt(count)) {
|
|
819
|
+
try {
|
|
820
|
+
return await useAsynchronousPartition(count).collect(this.source());
|
|
821
|
+
}
|
|
822
|
+
catch (error) {
|
|
823
|
+
throw new Error("Uncaught error on partition.");
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
throw new TypeError("Count must be a BigInt.");
|
|
827
|
+
}
|
|
828
|
+
async partitionBy(classifier) {
|
|
829
|
+
if (isFunction(classifier)) {
|
|
830
|
+
try {
|
|
831
|
+
let collector = useAsynchronousPartitionBy(classifier);
|
|
832
|
+
return await collector.collect(this.source());
|
|
833
|
+
}
|
|
834
|
+
catch (error) {
|
|
835
|
+
throw new Error("Uncaught error on partitionBy.");
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
throw new TypeError("Classifier must be a function.");
|
|
839
|
+
}
|
|
840
|
+
async reduce(argument1, argument2, argument3) {
|
|
841
|
+
if (isFunction(argument1) && invalidate(argument2) && invalidate(argument3)) {
|
|
842
|
+
try {
|
|
843
|
+
let accumulator = argument1;
|
|
844
|
+
return await useAsynchronousReduce(accumulator).collect(this.source());
|
|
845
|
+
}
|
|
846
|
+
catch (error) {
|
|
847
|
+
throw new Error("Uncaught error on reduce.");
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
else if (validate(argument1) && isFunction(argument2) && invalidate(argument3)) {
|
|
851
|
+
try {
|
|
852
|
+
let identity = argument1;
|
|
853
|
+
let accumulator = argument2;
|
|
854
|
+
return await useAsynchronousReduce(identity, accumulator).collect(this.source());
|
|
855
|
+
}
|
|
856
|
+
catch (error) {
|
|
857
|
+
throw new Error("Uncaught error on reduce.");
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
else if (validate(argument1) && isFunction(argument2) && isFunction(argument3)) {
|
|
861
|
+
try {
|
|
862
|
+
let identity = argument1;
|
|
863
|
+
let accumulator = argument2;
|
|
864
|
+
let finisher = argument3;
|
|
865
|
+
return await useAsynchronousReduce(identity, accumulator, finisher).collect(this.source());
|
|
866
|
+
}
|
|
867
|
+
catch (error) {
|
|
868
|
+
throw new Error("Uncaught error on reduce.");
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
else {
|
|
872
|
+
throw new TypeError("Invalid arguments.");
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
semantic() {
|
|
876
|
+
let source = this.source();
|
|
877
|
+
if (isFunction(source)) {
|
|
878
|
+
try {
|
|
879
|
+
return new AsynchronousSemantic(source);
|
|
880
|
+
}
|
|
881
|
+
catch (error) {
|
|
882
|
+
throw new Error("Uncaught error on semantic.");
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
else {
|
|
886
|
+
throw new TypeError("Invalid source.");
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
async toArray() {
|
|
890
|
+
try {
|
|
891
|
+
return useAsynchronousToArray().collect(this.source());
|
|
892
|
+
}
|
|
893
|
+
catch (error) {
|
|
894
|
+
throw new Error("Uncaught error on toArray.");
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
async toMap(keyExtractor, valueExtractor = (element) => element) {
|
|
898
|
+
try {
|
|
899
|
+
return await useAsynchronousToMap(keyExtractor, valueExtractor).collect(this.source());
|
|
900
|
+
}
|
|
901
|
+
catch (error) {
|
|
902
|
+
throw new Error("Uncaught error on toMap.");
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
async toSet() {
|
|
906
|
+
try {
|
|
907
|
+
return await useAsynchronousToSet().collect(this.source());
|
|
908
|
+
}
|
|
909
|
+
catch (error) {
|
|
910
|
+
throw new Error("Uncaught error on toSet.");
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
async write(argument1, argument2) {
|
|
914
|
+
if (isObject(argument1)) {
|
|
915
|
+
try {
|
|
916
|
+
let stream = argument1;
|
|
917
|
+
if (isFunction(argument2)) {
|
|
918
|
+
let accumulator = argument2;
|
|
919
|
+
return await useAsynchronousWrite(stream, accumulator).collect(this.source());
|
|
920
|
+
}
|
|
921
|
+
else {
|
|
922
|
+
return await useAsynchronousWrite(stream).collect(this.source());
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
catch (error) {
|
|
926
|
+
throw new Error("Uncaught error on write.");
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
throw new TypeError("Invalid arguments.");
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
;
|
|
933
|
+
export class AsynchronousOrderedCollectable extends AsynchronousCollectable {
|
|
934
|
+
OrderedCollectable = AsynchronousOrderedCollectableSymbol;
|
|
935
|
+
buffer = [];
|
|
936
|
+
listeners = [];
|
|
937
|
+
complete = false;
|
|
938
|
+
[Symbol.toStringTag] = "AsynchronousOrderedCollectable";
|
|
939
|
+
constructor(argument1, argument2) {
|
|
940
|
+
super();
|
|
941
|
+
if (isFunction(argument1)) {
|
|
942
|
+
try {
|
|
943
|
+
if (isFunction(argument2)) {
|
|
944
|
+
let collector = useAsynchronousToArray();
|
|
945
|
+
collector.collect(argument1).then((elements) => {
|
|
946
|
+
this.buffer = elements.sort(argument2).map((element, index) => {
|
|
947
|
+
return {
|
|
948
|
+
element: element,
|
|
949
|
+
index: BigInt(index)
|
|
950
|
+
};
|
|
951
|
+
});
|
|
952
|
+
for (let listener of this.listeners) {
|
|
953
|
+
listener(this.buffer);
|
|
954
|
+
}
|
|
955
|
+
this.complete = true;
|
|
956
|
+
Object.freeze(this.complete);
|
|
957
|
+
Object.freeze(this.buffer);
|
|
958
|
+
});
|
|
959
|
+
}
|
|
960
|
+
else {
|
|
961
|
+
let collector = useAsynchronousToArray();
|
|
962
|
+
collector.collect(argument1).then((elements) => {
|
|
963
|
+
this.buffer = elements.sort(useCompare).map((element, index) => {
|
|
964
|
+
return {
|
|
965
|
+
element: element,
|
|
966
|
+
index: BigInt(index)
|
|
967
|
+
};
|
|
968
|
+
});
|
|
969
|
+
for (let listener of this.listeners) {
|
|
970
|
+
listener(this.buffer);
|
|
971
|
+
}
|
|
972
|
+
this.complete = true;
|
|
973
|
+
Object.freeze(this.complete);
|
|
974
|
+
Object.freeze(this.buffer);
|
|
975
|
+
});
|
|
976
|
+
}
|
|
977
|
+
Object.defineProperties(this, {
|
|
978
|
+
"AsynchronousOrderedCollectable": {
|
|
979
|
+
value: AsynchronousOrderedCollectableSymbol,
|
|
980
|
+
writable: false,
|
|
981
|
+
enumerable: false,
|
|
982
|
+
configurable: false
|
|
983
|
+
},
|
|
984
|
+
"buffer": {
|
|
985
|
+
value: this.buffer,
|
|
986
|
+
writable: false,
|
|
987
|
+
enumerable: false,
|
|
988
|
+
configurable: false
|
|
989
|
+
}
|
|
990
|
+
});
|
|
991
|
+
}
|
|
992
|
+
catch (error) {
|
|
993
|
+
throw new Error("Uncaught error on creating buffer.");
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
else {
|
|
997
|
+
throw new TypeError("Source must be an iterable or a generator function.");
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
async *[Symbol.asyncIterator]() {
|
|
1001
|
+
for await (let element of await this.toArray()) {
|
|
1002
|
+
yield element;
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
async findAny() {
|
|
1006
|
+
if (this.complete === true) {
|
|
1007
|
+
return await new Promise((resolve, reject) => {
|
|
1008
|
+
try {
|
|
1009
|
+
if (this.buffer.length > 0) {
|
|
1010
|
+
for (let { element } of this.buffer) {
|
|
1011
|
+
if (Math.random() < 0.5) {
|
|
1012
|
+
resolve(element);
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
catch (error) {
|
|
1018
|
+
reject(error);
|
|
1019
|
+
}
|
|
1020
|
+
});
|
|
1021
|
+
}
|
|
1022
|
+
return await new Promise((resolve, reject) => {
|
|
1023
|
+
try {
|
|
1024
|
+
this.listeners.push((buffer) => {
|
|
1025
|
+
if (this.buffer.length > 0) {
|
|
1026
|
+
for (let { element } of buffer) {
|
|
1027
|
+
if (Math.random() < 0.5) {
|
|
1028
|
+
resolve(element);
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
});
|
|
1033
|
+
}
|
|
1034
|
+
catch (error) {
|
|
1035
|
+
reject(error);
|
|
1036
|
+
}
|
|
1037
|
+
});
|
|
1038
|
+
}
|
|
1039
|
+
async findAt(target) {
|
|
1040
|
+
if (isBigInt(target)) {
|
|
1041
|
+
return await new Promise((resolve, reject) => {
|
|
1042
|
+
try {
|
|
1043
|
+
if (this.complete === true) {
|
|
1044
|
+
if (this.buffer.length > 0) {
|
|
1045
|
+
for (let { element, index } of this.buffer) {
|
|
1046
|
+
if (index === target) {
|
|
1047
|
+
resolve(element);
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
else {
|
|
1053
|
+
this.listeners.push((buffer) => {
|
|
1054
|
+
if (this.buffer.length > 0) {
|
|
1055
|
+
for (let { element, index } of buffer) {
|
|
1056
|
+
if (index === target) {
|
|
1057
|
+
resolve(element);
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
});
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
catch (error) {
|
|
1065
|
+
reject(error);
|
|
1066
|
+
}
|
|
1067
|
+
});
|
|
1068
|
+
}
|
|
1069
|
+
else if (isNumber(target)) {
|
|
1070
|
+
return await new Promise((resolve, reject) => {
|
|
1071
|
+
try {
|
|
1072
|
+
if (this.complete === true) {
|
|
1073
|
+
if (this.buffer.length > 0) {
|
|
1074
|
+
for (let { element, index } of this.buffer) {
|
|
1075
|
+
if (Number(index) === target) {
|
|
1076
|
+
resolve(element);
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
else {
|
|
1082
|
+
this.listeners.push((buffer) => {
|
|
1083
|
+
if (this.buffer.length > 0) {
|
|
1084
|
+
for (let { element, index } of buffer) {
|
|
1085
|
+
if (Number(index) === target) {
|
|
1086
|
+
resolve(element);
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
});
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
catch (error) {
|
|
1094
|
+
reject(error);
|
|
1095
|
+
}
|
|
1096
|
+
});
|
|
1097
|
+
}
|
|
1098
|
+
throw new TypeError("Invalid arguments.");
|
|
1099
|
+
}
|
|
1100
|
+
async findFirst() {
|
|
1101
|
+
return await new Promise((resolve, reject) => {
|
|
1102
|
+
try {
|
|
1103
|
+
if (this.complete === true) {
|
|
1104
|
+
if (this.buffer.length > 0) {
|
|
1105
|
+
resolve(this.buffer[0].element);
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
else {
|
|
1109
|
+
this.listeners.push((buffer) => {
|
|
1110
|
+
if (buffer.length > 0) {
|
|
1111
|
+
resolve(buffer[0].element);
|
|
1112
|
+
}
|
|
1113
|
+
});
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
catch (error) {
|
|
1117
|
+
reject(error);
|
|
1118
|
+
}
|
|
1119
|
+
});
|
|
1120
|
+
}
|
|
1121
|
+
async findLast() {
|
|
1122
|
+
return await new Promise((resolve, reject) => {
|
|
1123
|
+
try {
|
|
1124
|
+
if (this.complete === true) {
|
|
1125
|
+
if (this.buffer.length > 0) {
|
|
1126
|
+
resolve(this.buffer[this.buffer.length - 1].element);
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
else {
|
|
1130
|
+
this.listeners.push((buffer) => {
|
|
1131
|
+
if (buffer.length > 0) {
|
|
1132
|
+
resolve(buffer[this.buffer.length - 1].element);
|
|
1133
|
+
}
|
|
1134
|
+
});
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
catch (error) {
|
|
1138
|
+
reject(error);
|
|
1139
|
+
}
|
|
1140
|
+
});
|
|
1141
|
+
}
|
|
1142
|
+
async findMaximum(argument1) {
|
|
1143
|
+
if (isFunction(argument1)) {
|
|
1144
|
+
let comparator = argument1;
|
|
1145
|
+
return await new Promise((resolve, reject) => {
|
|
1146
|
+
try {
|
|
1147
|
+
if (this.complete === true) {
|
|
1148
|
+
if (this.buffer.length > 0) {
|
|
1149
|
+
resolve(this.buffer.map((indexed) => indexed.element).sort(comparator)[this.buffer.length - 1]);
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
else {
|
|
1153
|
+
this.listeners.push((buffer) => {
|
|
1154
|
+
if (buffer.length > 0) {
|
|
1155
|
+
resolve(this.buffer.map((indexed) => indexed.element).sort(comparator)[this.buffer.length - 1]);
|
|
1156
|
+
}
|
|
1157
|
+
});
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
catch (error) {
|
|
1161
|
+
reject(error);
|
|
1162
|
+
}
|
|
1163
|
+
});
|
|
1164
|
+
}
|
|
1165
|
+
else {
|
|
1166
|
+
let comparator = (a, b) => Number(a.index - b.index);
|
|
1167
|
+
return await new Promise((resolve, reject) => {
|
|
1168
|
+
try {
|
|
1169
|
+
if (this.complete === true) {
|
|
1170
|
+
if (this.buffer.length > 0) {
|
|
1171
|
+
resolve(this.buffer.sort(comparator).map((indexed) => indexed.element)[this.buffer.length - 1]);
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
else {
|
|
1175
|
+
this.listeners.push((buffer) => {
|
|
1176
|
+
if (buffer.length > 0) {
|
|
1177
|
+
resolve(this.buffer.sort(comparator).map((indexed) => indexed.element)[this.buffer.length - 1]);
|
|
1178
|
+
}
|
|
1179
|
+
});
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
catch (error) {
|
|
1183
|
+
reject(error);
|
|
1184
|
+
}
|
|
1185
|
+
});
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
async findMinimum(argument1) {
|
|
1189
|
+
if (isFunction(argument1)) {
|
|
1190
|
+
let comparator = argument1;
|
|
1191
|
+
return await new Promise((resolve, reject) => {
|
|
1192
|
+
try {
|
|
1193
|
+
if (this.complete === true) {
|
|
1194
|
+
if (this.buffer.length > 0) {
|
|
1195
|
+
resolve(this.buffer.map((indexed) => indexed.element).sort(comparator)[0]);
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
else {
|
|
1199
|
+
this.listeners.push((buffer) => {
|
|
1200
|
+
if (buffer.length > 0) {
|
|
1201
|
+
resolve(this.buffer.map((indexed) => indexed.element).sort(comparator)[0]);
|
|
1202
|
+
}
|
|
1203
|
+
});
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
catch (error) {
|
|
1207
|
+
reject(error);
|
|
1208
|
+
}
|
|
1209
|
+
});
|
|
1210
|
+
}
|
|
1211
|
+
else {
|
|
1212
|
+
let comparator = (a, b) => Number(a.index - b.index);
|
|
1213
|
+
return await new Promise((resolve, reject) => {
|
|
1214
|
+
try {
|
|
1215
|
+
if (this.complete === true) {
|
|
1216
|
+
if (this.buffer.length > 0) {
|
|
1217
|
+
resolve(this.buffer.sort(comparator).map((indexed) => indexed.element)[0]);
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
else {
|
|
1221
|
+
this.listeners.push((buffer) => {
|
|
1222
|
+
if (buffer.length > 0) {
|
|
1223
|
+
resolve(this.buffer.sort(comparator).map((indexed) => indexed.element)[0]);
|
|
1224
|
+
}
|
|
1225
|
+
});
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
catch (error) {
|
|
1229
|
+
reject(error);
|
|
1230
|
+
}
|
|
1231
|
+
});
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
1234
|
+
source() {
|
|
1235
|
+
return async (accept, interrupt) => {
|
|
1236
|
+
return await new Promise((resolve, reject) => {
|
|
1237
|
+
try {
|
|
1238
|
+
if (this.complete === true) {
|
|
1239
|
+
for (let { index, element } of this.buffer) {
|
|
1240
|
+
if (interrupt(element, index)) {
|
|
1241
|
+
break;
|
|
1242
|
+
}
|
|
1243
|
+
accept(element, index);
|
|
1244
|
+
}
|
|
1245
|
+
resolve();
|
|
1246
|
+
}
|
|
1247
|
+
else {
|
|
1248
|
+
this.listeners.push((buffer) => {
|
|
1249
|
+
for (let { index, element } of buffer) {
|
|
1250
|
+
if (interrupt(element, index)) {
|
|
1251
|
+
break;
|
|
1252
|
+
}
|
|
1253
|
+
accept(element, index);
|
|
1254
|
+
}
|
|
1255
|
+
});
|
|
1256
|
+
resolve();
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
catch (error) {
|
|
1260
|
+
reject(error);
|
|
1261
|
+
}
|
|
1262
|
+
});
|
|
1263
|
+
};
|
|
1264
|
+
}
|
|
1265
|
+
async isEmpty() {
|
|
1266
|
+
return new Promise((resolve) => {
|
|
1267
|
+
this.listeners.push((buffer) => {
|
|
1268
|
+
resolve(buffer.length === 0);
|
|
1269
|
+
});
|
|
1270
|
+
});
|
|
1271
|
+
}
|
|
1272
|
+
async count() {
|
|
1273
|
+
if (this.complete === true) {
|
|
1274
|
+
return BigInt(this.buffer.length);
|
|
1275
|
+
}
|
|
1276
|
+
return await new Promise((resolve) => {
|
|
1277
|
+
this.listeners.push((buffer) => {
|
|
1278
|
+
resolve(BigInt(buffer.length));
|
|
1279
|
+
});
|
|
1280
|
+
});
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
;
|
|
1284
|
+
export class AsynchronousUnorderedCollectable extends AsynchronousCollectable {
|
|
1285
|
+
AsynchronousUnorderedCollectable = AsynchronousUnorderedCollectableSymbol;
|
|
1286
|
+
[Symbol.toStringTag] = "AsynchronousUnorderedCollectable";
|
|
1287
|
+
buffer = new Map();
|
|
1288
|
+
complete = false;
|
|
1289
|
+
listeners = [];
|
|
1290
|
+
constructor(argument1) {
|
|
1291
|
+
super();
|
|
1292
|
+
if (isFunction(argument1)) {
|
|
1293
|
+
let generator = argument1;
|
|
1294
|
+
generator((element, index) => {
|
|
1295
|
+
this.buffer.set(index, element);
|
|
1296
|
+
}, () => false).then(() => {
|
|
1297
|
+
for (let listener of this.listeners) {
|
|
1298
|
+
listener(this.buffer);
|
|
1299
|
+
}
|
|
1300
|
+
this.complete = true;
|
|
1301
|
+
Object.freeze(this.complete);
|
|
1302
|
+
Object.freeze(this.buffer);
|
|
1303
|
+
});
|
|
1304
|
+
Object.defineProperties(this, {
|
|
1305
|
+
"AsynchronousUnorderedCollectable": {
|
|
1306
|
+
value: AsynchronousUnorderedCollectableSymbol,
|
|
1307
|
+
writable: false,
|
|
1308
|
+
enumerable: false,
|
|
1309
|
+
configurable: false
|
|
1310
|
+
}
|
|
1311
|
+
});
|
|
1312
|
+
}
|
|
1313
|
+
else {
|
|
1314
|
+
throw new TypeError("Source must be an iterable or a generator function.");
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
source() {
|
|
1318
|
+
return async (accept, interrupt) => {
|
|
1319
|
+
return await new Promise((resolve, reject) => {
|
|
1320
|
+
try {
|
|
1321
|
+
if (this.complete === true) {
|
|
1322
|
+
for (let [index, element] of this.buffer) {
|
|
1323
|
+
if (interrupt(element, index)) {
|
|
1324
|
+
break;
|
|
1325
|
+
}
|
|
1326
|
+
accept(element, index);
|
|
1327
|
+
}
|
|
1328
|
+
resolve();
|
|
1329
|
+
}
|
|
1330
|
+
else {
|
|
1331
|
+
this.listeners.push((buffer) => {
|
|
1332
|
+
for (let [index, element] of buffer) {
|
|
1333
|
+
if (interrupt(element, index)) {
|
|
1334
|
+
break;
|
|
1335
|
+
}
|
|
1336
|
+
accept(element, index);
|
|
1337
|
+
}
|
|
1338
|
+
});
|
|
1339
|
+
resolve();
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
catch (error) {
|
|
1343
|
+
reject(error);
|
|
1344
|
+
}
|
|
1345
|
+
});
|
|
1346
|
+
};
|
|
1347
|
+
}
|
|
1348
|
+
async *[Symbol.asyncIterator]() {
|
|
1349
|
+
for await (let element of await this.toArray()) {
|
|
1350
|
+
yield element;
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
;
|
|
1355
|
+
export class AsynchronousStatistics extends AsynchronousOrderedCollectable {
|
|
1356
|
+
AsynchronousStatistics = AsynchronousStatisticsSymbol;
|
|
1357
|
+
[Symbol.toStringTag] = "AsynchronousStatistics";
|
|
1358
|
+
constructor(parameter, comparator) {
|
|
1359
|
+
super(parameter, validate(comparator) ? comparator : useCompare);
|
|
1360
|
+
Object.defineProperties(this, {
|
|
1361
|
+
"AsynchronousStatistics": {
|
|
1362
|
+
value: AsynchronousStatisticsSymbol,
|
|
1363
|
+
enumerable: false,
|
|
1364
|
+
writable: false,
|
|
1365
|
+
configurable: false
|
|
1366
|
+
}
|
|
1367
|
+
});
|
|
1368
|
+
}
|
|
1369
|
+
async *[Symbol.asyncIterator]() {
|
|
1370
|
+
for await (let element of await this.toArray()) {
|
|
1371
|
+
yield element;
|
|
1372
|
+
}
|
|
1373
|
+
}
|
|
1374
|
+
async frequency() {
|
|
1375
|
+
return await useAsynchronousFrequency().collect(this.source());
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
;
|
|
1379
|
+
export class AsynchronousBigIntStatistics extends AsynchronousStatistics {
|
|
1380
|
+
BigIntStatistics = AsynchronousBigIntStatisticsSymbol;
|
|
1381
|
+
[Symbol.toStringTag] = "AsynchronousBigIntStatistics";
|
|
1382
|
+
constructor(parameter, comparator) {
|
|
1383
|
+
super(parameter, comparator || useCompare);
|
|
1384
|
+
Object.defineProperties(this, {
|
|
1385
|
+
"AsynchronousBigIntStatistics": {
|
|
1386
|
+
value: AsynchronousBigIntStatisticsSymbol,
|
|
1387
|
+
enumerable: false,
|
|
1388
|
+
writable: false,
|
|
1389
|
+
configurable: false
|
|
1390
|
+
}
|
|
1391
|
+
});
|
|
1392
|
+
}
|
|
1393
|
+
async *[Symbol.asyncIterator]() {
|
|
1394
|
+
for await (let element of await this.toArray()) {
|
|
1395
|
+
yield element;
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
async average(argument1) {
|
|
1399
|
+
if (await this.isEmpty()) {
|
|
1400
|
+
return 0n;
|
|
1401
|
+
}
|
|
1402
|
+
try {
|
|
1403
|
+
let mapper = isFunction(argument1) ? argument1 : useToBigInt;
|
|
1404
|
+
return await useAsynchronousBigIntAverage(mapper).collect(this.source());
|
|
1405
|
+
}
|
|
1406
|
+
catch (error) {
|
|
1407
|
+
throw new Error("Uncaught error on average.");
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
async range(argument1) {
|
|
1411
|
+
if (await this.isEmpty()) {
|
|
1412
|
+
return 0n;
|
|
1413
|
+
}
|
|
1414
|
+
try {
|
|
1415
|
+
let mapper = isFunction(argument1) ? argument1 : useToBigInt;
|
|
1416
|
+
let minimum = await this.findFirst();
|
|
1417
|
+
let maximum = await this.findLast();
|
|
1418
|
+
let difference = mapper(maximum) - mapper(minimum);
|
|
1419
|
+
return difference < 0 ? -difference : difference;
|
|
1420
|
+
}
|
|
1421
|
+
catch (error) {
|
|
1422
|
+
throw new Error("Uncaught error on range.");
|
|
1423
|
+
}
|
|
1424
|
+
}
|
|
1425
|
+
async variance(argument1) {
|
|
1426
|
+
if (await this.isEmpty() || await this.count() === 1n) {
|
|
1427
|
+
return 0n;
|
|
1428
|
+
}
|
|
1429
|
+
try {
|
|
1430
|
+
let mapper = isFunction(argument1) ? argument1 : useToBigInt;
|
|
1431
|
+
return await useAsynchronousBigIntVariance(mapper).collect(this.source());
|
|
1432
|
+
}
|
|
1433
|
+
catch (error) {
|
|
1434
|
+
throw new Error("Uncaught error on variance.");
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
async standardDeviation(argument1) {
|
|
1438
|
+
try {
|
|
1439
|
+
let mapper = isFunction(argument1) ? argument1 : useToBigInt;
|
|
1440
|
+
let variance = await this.variance(mapper);
|
|
1441
|
+
return BigInt(Math.sqrt(Number(variance)));
|
|
1442
|
+
}
|
|
1443
|
+
catch (error) {
|
|
1444
|
+
throw new Error("Uncaught error on standardDeviation.");
|
|
1445
|
+
}
|
|
1446
|
+
}
|
|
1447
|
+
async mean(argument1) {
|
|
1448
|
+
if (await this.isEmpty()) {
|
|
1449
|
+
return 0n;
|
|
1450
|
+
}
|
|
1451
|
+
try {
|
|
1452
|
+
let mapper = isFunction(argument1) ? argument1 : useToBigInt;
|
|
1453
|
+
return await useAsynchronousBigIntAverage(mapper).collect(this.source());
|
|
1454
|
+
}
|
|
1455
|
+
catch (error) {
|
|
1456
|
+
throw new Error("Uncaught error on mean.");
|
|
1457
|
+
}
|
|
1458
|
+
}
|
|
1459
|
+
async median(argument1) {
|
|
1460
|
+
if (await this.isEmpty()) {
|
|
1461
|
+
return 0n;
|
|
1462
|
+
}
|
|
1463
|
+
try {
|
|
1464
|
+
let mapper = isFunction(argument1) ? argument1 : useToBigInt;
|
|
1465
|
+
return useAsynchronousBigIntMedian(mapper).collect(this.source());
|
|
1466
|
+
}
|
|
1467
|
+
catch (error) {
|
|
1468
|
+
throw new Error("Uncaught error on median.");
|
|
1469
|
+
}
|
|
1470
|
+
}
|
|
1471
|
+
async mode(argument1) {
|
|
1472
|
+
if (await this.isEmpty()) {
|
|
1473
|
+
return 0n;
|
|
1474
|
+
}
|
|
1475
|
+
try {
|
|
1476
|
+
let mapper = isFunction(argument1) ? argument1 : useToBigInt;
|
|
1477
|
+
return useAsynchronousBigIntMode(mapper).collect(this.source());
|
|
1478
|
+
}
|
|
1479
|
+
catch (error) {
|
|
1480
|
+
throw new Error("Uncaught error on mode.");
|
|
1481
|
+
}
|
|
1482
|
+
}
|
|
1483
|
+
async summate(argument1) {
|
|
1484
|
+
if (await this.isEmpty()) {
|
|
1485
|
+
return 0n;
|
|
1486
|
+
}
|
|
1487
|
+
try {
|
|
1488
|
+
let mapper = isFunction(argument1) ? argument1 : useToBigInt;
|
|
1489
|
+
return await useAsynchronousBigIntSummate(mapper).collect(this.source());
|
|
1490
|
+
}
|
|
1491
|
+
catch (error) {
|
|
1492
|
+
throw new Error("Uncaught error on summate.");
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1495
|
+
async quantile(quantile, argument1) {
|
|
1496
|
+
if (await this.isEmpty()) {
|
|
1497
|
+
return 0n;
|
|
1498
|
+
}
|
|
1499
|
+
if (!isNumber(quantile) || quantile < 0 || quantile > 1) {
|
|
1500
|
+
throw new RangeError("Invalid quantile.");
|
|
1501
|
+
}
|
|
1502
|
+
try {
|
|
1503
|
+
let mapper = isFunction(argument1) ? argument1 : useToBigInt;
|
|
1504
|
+
let count = Number(this.count());
|
|
1505
|
+
let index = Math.floor(quantile * count);
|
|
1506
|
+
if (index === count) {
|
|
1507
|
+
index--;
|
|
1508
|
+
}
|
|
1509
|
+
let value = mapper(await this.findAt(index));
|
|
1510
|
+
return value;
|
|
1511
|
+
}
|
|
1512
|
+
catch (error) {
|
|
1513
|
+
throw new Error("Uncaught error on quantile.");
|
|
1514
|
+
}
|
|
1515
|
+
}
|
|
1516
|
+
async interquartileRange(argument1) {
|
|
1517
|
+
if (await this.isEmpty()) {
|
|
1518
|
+
return 0n;
|
|
1519
|
+
}
|
|
1520
|
+
try {
|
|
1521
|
+
let mapper = isFunction(argument1) ? argument1 : useToBigInt;
|
|
1522
|
+
let lower = await this.quantile(0.25, mapper);
|
|
1523
|
+
let upper = await this.quantile(0.75, mapper);
|
|
1524
|
+
return upper - lower;
|
|
1525
|
+
}
|
|
1526
|
+
catch (error) {
|
|
1527
|
+
throw new Error("Uncaught error on interquartileRange.");
|
|
1528
|
+
}
|
|
1529
|
+
}
|
|
1530
|
+
async skewness(argument1) {
|
|
1531
|
+
if (await this.isEmpty()) {
|
|
1532
|
+
return 0n;
|
|
1533
|
+
}
|
|
1534
|
+
try {
|
|
1535
|
+
let mapper = isFunction(argument1) ? argument1 : useToBigInt;
|
|
1536
|
+
let mean = await this.mean(mapper);
|
|
1537
|
+
let standardDeviation = await this.standardDeviation(mapper);
|
|
1538
|
+
if (standardDeviation === 0n) {
|
|
1539
|
+
return 0n;
|
|
1540
|
+
}
|
|
1541
|
+
let data = (await this.toArray()).map((element) => mapper(element));
|
|
1542
|
+
let summate = 0n;
|
|
1543
|
+
for (let value of data) {
|
|
1544
|
+
let z = value - mean;
|
|
1545
|
+
summate += z * z * z;
|
|
1546
|
+
}
|
|
1547
|
+
return summate / BigInt(data.length);
|
|
1548
|
+
}
|
|
1549
|
+
catch (error) {
|
|
1550
|
+
throw new Error("Uncaught error on skewness.");
|
|
1551
|
+
}
|
|
1552
|
+
}
|
|
1553
|
+
async kurtosis(argument1) {
|
|
1554
|
+
if (await this.isEmpty()) {
|
|
1555
|
+
return 0n;
|
|
1556
|
+
}
|
|
1557
|
+
try {
|
|
1558
|
+
let mapper = isFunction(argument1) ? argument1 : useToBigInt;
|
|
1559
|
+
let mean = await this.mean(mapper);
|
|
1560
|
+
let standardDeviation = await this.standardDeviation(mapper);
|
|
1561
|
+
if (standardDeviation === 0n) {
|
|
1562
|
+
return 0n;
|
|
1563
|
+
}
|
|
1564
|
+
let data = (await this.toArray()).map((element) => mapper(element));
|
|
1565
|
+
let summate = 0n;
|
|
1566
|
+
let count = data.length;
|
|
1567
|
+
for (let value of data) {
|
|
1568
|
+
let z = value - mean;
|
|
1569
|
+
summate += z * z * z * z;
|
|
1570
|
+
}
|
|
1571
|
+
return summate / BigInt(count * count) - 3n;
|
|
1572
|
+
}
|
|
1573
|
+
catch (error) {
|
|
1574
|
+
throw new Error("Uncaught error on kurtosis.");
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1577
|
+
}
|
|
1578
|
+
;
|
|
1579
|
+
export class AsynchronousNumericStatistics extends AsynchronousStatistics {
|
|
1580
|
+
AsynchronousNumericStatistics = AsynchronousNumericStatisticsSymbol;
|
|
1581
|
+
[Symbol.toStringTag] = "AsynchronousNumericStatistics";
|
|
1582
|
+
constructor(parameter, comparator) {
|
|
1583
|
+
super(parameter, comparator || useCompare);
|
|
1584
|
+
Object.defineProperties(this, {
|
|
1585
|
+
"AsynchronousNumericStatistics": {
|
|
1586
|
+
value: AsynchronousNumericStatisticsSymbol,
|
|
1587
|
+
enumerable: false,
|
|
1588
|
+
writable: false,
|
|
1589
|
+
configurable: false
|
|
1590
|
+
}
|
|
1591
|
+
});
|
|
1592
|
+
}
|
|
1593
|
+
async *[Symbol.asyncIterator]() {
|
|
1594
|
+
for await (let element of await this.toArray()) {
|
|
1595
|
+
yield element;
|
|
1596
|
+
}
|
|
1597
|
+
}
|
|
1598
|
+
async average(mapper) {
|
|
1599
|
+
if (await this.isEmpty()) {
|
|
1600
|
+
return 0;
|
|
1601
|
+
}
|
|
1602
|
+
try {
|
|
1603
|
+
if (isFunction(mapper)) {
|
|
1604
|
+
return useAsynchronousNumericAverage(mapper).collect(this.source());
|
|
1605
|
+
}
|
|
1606
|
+
return useAsynchronousNumericAverage().collect(this.source());
|
|
1607
|
+
}
|
|
1608
|
+
catch (error) {
|
|
1609
|
+
throw new Error("Uncaught error on average.");
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
async range(argument1) {
|
|
1613
|
+
if (await this.isEmpty()) {
|
|
1614
|
+
return 0;
|
|
1615
|
+
}
|
|
1616
|
+
try {
|
|
1617
|
+
if (await this.count() === 1n) {
|
|
1618
|
+
return 0;
|
|
1619
|
+
}
|
|
1620
|
+
let mapper = isFunction(argument1) ? argument1 : useToNumber;
|
|
1621
|
+
let minimum = await this.findFirst();
|
|
1622
|
+
let maximum = await this.findLast();
|
|
1623
|
+
return mapper(maximum) - mapper(minimum);
|
|
1624
|
+
}
|
|
1625
|
+
catch (error) {
|
|
1626
|
+
throw new Error("Uncaught error on range.");
|
|
1627
|
+
}
|
|
1628
|
+
}
|
|
1629
|
+
async variance(argument1) {
|
|
1630
|
+
if (await this.isEmpty() || await this.count() === 1n) {
|
|
1631
|
+
return 0;
|
|
1632
|
+
}
|
|
1633
|
+
try {
|
|
1634
|
+
let mapper = isFunction(argument1) ? argument1 : useToNumber;
|
|
1635
|
+
return await useAsynchronousNumericVariance(mapper).collect(this.source());
|
|
1636
|
+
}
|
|
1637
|
+
catch (error) {
|
|
1638
|
+
throw new Error("Uncaught error on variance.");
|
|
1639
|
+
}
|
|
1640
|
+
}
|
|
1641
|
+
async standardDeviation(argument1) {
|
|
1642
|
+
try {
|
|
1643
|
+
let mapper = isFunction(argument1) ? argument1 : useToNumber;
|
|
1644
|
+
return await useAsynchronousNumericStandardDeviation(mapper).collect(this.source());
|
|
1645
|
+
}
|
|
1646
|
+
catch (error) {
|
|
1647
|
+
throw new Error("Uncaught error on standardDeviation.");
|
|
1648
|
+
}
|
|
1649
|
+
}
|
|
1650
|
+
async mean(argument1) {
|
|
1651
|
+
if (await this.isEmpty()) {
|
|
1652
|
+
return 0;
|
|
1653
|
+
}
|
|
1654
|
+
try {
|
|
1655
|
+
let mapper = isFunction(argument1) ? argument1 : useToNumber;
|
|
1656
|
+
return useAsynchronousNumericAverage(mapper).collect(this.source());
|
|
1657
|
+
}
|
|
1658
|
+
catch (error) {
|
|
1659
|
+
throw new Error("Uncaught error on mean.");
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
async median(argument1) {
|
|
1663
|
+
if (await this.isEmpty()) {
|
|
1664
|
+
return 0;
|
|
1665
|
+
}
|
|
1666
|
+
try {
|
|
1667
|
+
let mapper = isFunction(argument1) ? argument1 : useToNumber;
|
|
1668
|
+
return await useAsynchronousNumericMedian(mapper).collect(this.source());
|
|
1669
|
+
}
|
|
1670
|
+
catch (error) {
|
|
1671
|
+
throw new Error("Uncaught error on median.");
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1674
|
+
async mode(argument1) {
|
|
1675
|
+
if (await this.isEmpty()) {
|
|
1676
|
+
return 0;
|
|
1677
|
+
}
|
|
1678
|
+
try {
|
|
1679
|
+
let mapper = isFunction(argument1) ? argument1 : useToNumber;
|
|
1680
|
+
return await useAsynchronousNumericMode(mapper).collect(this.source());
|
|
1681
|
+
}
|
|
1682
|
+
catch (error) {
|
|
1683
|
+
throw new Error("Uncaught error on mode.");
|
|
1684
|
+
}
|
|
1685
|
+
}
|
|
1686
|
+
async summate(argument1) {
|
|
1687
|
+
if (await this.isEmpty()) {
|
|
1688
|
+
return 0;
|
|
1689
|
+
}
|
|
1690
|
+
try {
|
|
1691
|
+
let mapper = isFunction(argument1) ? argument1 : useToNumber;
|
|
1692
|
+
return useAsynchronousNumericSummate(mapper).collect(this.source());
|
|
1693
|
+
}
|
|
1694
|
+
catch (error) {
|
|
1695
|
+
throw new Error("Uncaught error on summate.");
|
|
1696
|
+
}
|
|
1697
|
+
}
|
|
1698
|
+
async quantile(quantile, argument1) {
|
|
1699
|
+
if (await this.isEmpty()) {
|
|
1700
|
+
return 0;
|
|
1701
|
+
}
|
|
1702
|
+
if (quantile < 0 || quantile > 1) {
|
|
1703
|
+
throw new RangeError("Invalid quantile.");
|
|
1704
|
+
}
|
|
1705
|
+
try {
|
|
1706
|
+
let mapper = isFunction(argument1) ? argument1 : useToNumber;
|
|
1707
|
+
let count = Number(await this.count());
|
|
1708
|
+
let index = Math.floor(quantile * count);
|
|
1709
|
+
if (index === count) {
|
|
1710
|
+
index--;
|
|
1711
|
+
}
|
|
1712
|
+
let value = mapper(await this.findAt(index));
|
|
1713
|
+
return value;
|
|
1714
|
+
}
|
|
1715
|
+
catch (error) {
|
|
1716
|
+
throw new Error("Uncaught error on quantile.");
|
|
1717
|
+
}
|
|
1718
|
+
}
|
|
1719
|
+
async interquartileRange(argument1) {
|
|
1720
|
+
if (await this.isEmpty()) {
|
|
1721
|
+
return 0;
|
|
1722
|
+
}
|
|
1723
|
+
try {
|
|
1724
|
+
let mapper = isFunction(argument1) ? argument1 : useToNumber;
|
|
1725
|
+
let lower = await this.quantile(0.25, mapper);
|
|
1726
|
+
let upper = await this.quantile(0.75, mapper);
|
|
1727
|
+
return upper - lower;
|
|
1728
|
+
}
|
|
1729
|
+
catch (error) {
|
|
1730
|
+
throw new Error("Uncaught error on interquartileRange.");
|
|
1731
|
+
}
|
|
1732
|
+
}
|
|
1733
|
+
async skewness(argument1) {
|
|
1734
|
+
if (await this.isEmpty()) {
|
|
1735
|
+
return 0;
|
|
1736
|
+
}
|
|
1737
|
+
try {
|
|
1738
|
+
let mapper = isFunction(argument1) ? argument1 : useToNumber;
|
|
1739
|
+
let mean = await this.mean(mapper);
|
|
1740
|
+
let standardDeviation = await this.standardDeviation(mapper);
|
|
1741
|
+
if (standardDeviation === 0) {
|
|
1742
|
+
return 0;
|
|
1743
|
+
}
|
|
1744
|
+
let data = (await this.toArray()).map((element) => mapper(element));
|
|
1745
|
+
let summate = 0;
|
|
1746
|
+
for (let value of data) {
|
|
1747
|
+
let z = (value - mean) / standardDeviation;
|
|
1748
|
+
summate += Math.pow(z, 3);
|
|
1749
|
+
}
|
|
1750
|
+
return summate / data.length;
|
|
1751
|
+
}
|
|
1752
|
+
catch (error) {
|
|
1753
|
+
throw new Error("Uncaught error on skewness.");
|
|
1754
|
+
}
|
|
1755
|
+
}
|
|
1756
|
+
async kurtosis(argument1) {
|
|
1757
|
+
if (await this.isEmpty()) {
|
|
1758
|
+
return 0;
|
|
1759
|
+
}
|
|
1760
|
+
try {
|
|
1761
|
+
let mapper = isFunction(argument1) ? argument1 : useToNumber;
|
|
1762
|
+
let mean = await this.mean(mapper);
|
|
1763
|
+
let standardDeviation = await this.standardDeviation(mapper);
|
|
1764
|
+
if (standardDeviation === 0) {
|
|
1765
|
+
return 0;
|
|
1766
|
+
}
|
|
1767
|
+
let data = (await this.toArray()).map((element) => mapper(element));
|
|
1768
|
+
let summate = 0;
|
|
1769
|
+
for (let value of data) {
|
|
1770
|
+
let z = (value - mean) / standardDeviation;
|
|
1771
|
+
summate += Math.pow(z, 4);
|
|
1772
|
+
}
|
|
1773
|
+
return summate / (data.length * data.length) - 3;
|
|
1774
|
+
}
|
|
1775
|
+
catch (error) {
|
|
1776
|
+
throw new Error("Uncaught error on kurtosis.");
|
|
1777
|
+
}
|
|
1778
|
+
}
|
|
1779
|
+
}
|
|
1780
|
+
;
|
|
1781
|
+
export class AsynchronousWindowCollectable extends AsynchronousOrderedCollectable {
|
|
1782
|
+
WindowCollectable = AsynchronousWindowCollectableSymbol;
|
|
1783
|
+
[Symbol.toStringTag] = "AsynchronousWindowCollectable";
|
|
1784
|
+
constructor(parameter, comparator = useCompare) {
|
|
1785
|
+
super(parameter, comparator);
|
|
1786
|
+
Object.defineProperties(this, {
|
|
1787
|
+
"AsynchronousWindowCollectable": {
|
|
1788
|
+
value: AsynchronousWindowCollectableSymbol,
|
|
1789
|
+
writable: false,
|
|
1790
|
+
enumerable: false,
|
|
1791
|
+
configurable: false
|
|
1792
|
+
}
|
|
1793
|
+
});
|
|
1794
|
+
}
|
|
1795
|
+
async *[Symbol.asyncIterator]() {
|
|
1796
|
+
for await (let element of await this.toArray()) {
|
|
1797
|
+
yield element;
|
|
1798
|
+
}
|
|
1799
|
+
}
|
|
1800
|
+
slide(size, step = 1n) {
|
|
1801
|
+
if (size > 0n && step > 0n) {
|
|
1802
|
+
return new AsynchronousSemantic(async (accepet, interrupt) => {
|
|
1803
|
+
return await new Promise((resolve, reject) => {
|
|
1804
|
+
try {
|
|
1805
|
+
let index = 0n;
|
|
1806
|
+
for (let start = 0n; start < BigInt(this.buffer.length); start += step) {
|
|
1807
|
+
let end = start + size;
|
|
1808
|
+
let inner = new AsynchronousSemantic(async (accept, interrupt) => {
|
|
1809
|
+
return await new Promise((resolve, reject) => {
|
|
1810
|
+
for (let index = start; index < end && index < BigInt(this.buffer.length); index++) {
|
|
1811
|
+
let indexed = this.buffer[Number(index)];
|
|
1812
|
+
if (invalidate(indexed)) {
|
|
1813
|
+
continue;
|
|
1814
|
+
}
|
|
1815
|
+
if (interrupt(indexed.element, index)) {
|
|
1816
|
+
reject(new Error("Interrupted."));
|
|
1817
|
+
break;
|
|
1818
|
+
}
|
|
1819
|
+
accept(indexed.element, index);
|
|
1820
|
+
}
|
|
1821
|
+
resolve();
|
|
1822
|
+
});
|
|
1823
|
+
});
|
|
1824
|
+
if (interrupt(inner, index)) {
|
|
1825
|
+
reject(new Error("Interrupted."));
|
|
1826
|
+
break;
|
|
1827
|
+
}
|
|
1828
|
+
accepet(inner, index);
|
|
1829
|
+
index++;
|
|
1830
|
+
}
|
|
1831
|
+
resolve();
|
|
1832
|
+
}
|
|
1833
|
+
catch (error) {
|
|
1834
|
+
throw new Error("Uncaught error on slide.");
|
|
1835
|
+
}
|
|
1836
|
+
});
|
|
1837
|
+
});
|
|
1838
|
+
}
|
|
1839
|
+
throw new RangeError("Invalid arguments.");
|
|
1840
|
+
}
|
|
1841
|
+
tumble(size) {
|
|
1842
|
+
if (isBigInt(size) && size > 0n) {
|
|
1843
|
+
try {
|
|
1844
|
+
return this.slide(size, size);
|
|
1845
|
+
}
|
|
1846
|
+
catch (error) {
|
|
1847
|
+
throw new Error("Uncaught error on tumble.");
|
|
1848
|
+
}
|
|
1849
|
+
}
|
|
1850
|
+
throw new RangeError("Invalid arguments.");
|
|
1851
|
+
}
|
|
1852
|
+
}
|
|
1853
|
+
;
|