semantic-typescript 0.3.3 → 0.3.7
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/collectable.d.ts +19 -24
- package/dist/collectable.js +329 -177
- package/dist/collector.d.ts +93 -16
- package/dist/collector.js +297 -107
- package/dist/factory.js +214 -159
- package/dist/guard.d.ts +3 -1
- package/dist/guard.js +14 -2
- package/dist/hook.d.ts +12 -0
- package/dist/hook.js +70 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/semantic.d.ts +2 -6
- package/dist/semantic.js +335 -185
- package/dist/statistics.d.ts +13 -17
- package/dist/statistics.js +204 -522
- package/dist/utility.d.ts +4 -0
- package/dist/utility.js +2 -1
- package/dist/window.d.ts +12 -0
- package/dist/window.js +60 -0
- package/package.json +1 -1
- package/readme.md +198 -21
package/dist/semantic.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { Collectable, OrderedCollectable, UnorderedCollectable
|
|
1
|
+
import { Collectable, OrderedCollectable, UnorderedCollectable } from "./collectable";
|
|
2
2
|
import { isBigInt, isCollectable, isFunction, isIterable, isNumber, isSemantic } from "./guard";
|
|
3
3
|
import { useCompare, useRandom } from "./hook";
|
|
4
4
|
import { BigIntStatistics, NumericStatistics } from "./statistics";
|
|
5
5
|
import { SemanticSymbol } from "./symbol";
|
|
6
6
|
import { validate } from "./utility";
|
|
7
|
+
import { WindowCollectable } from "./window";
|
|
7
8
|
export class Semantic {
|
|
8
9
|
generator;
|
|
9
10
|
Semantic = SemanticSymbol;
|
|
@@ -13,27 +14,37 @@ export class Semantic {
|
|
|
13
14
|
concat(other) {
|
|
14
15
|
if (isSemantic(other)) {
|
|
15
16
|
return new Semantic((accept, interrupt) => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
try {
|
|
18
|
+
let count = 0n;
|
|
19
|
+
this.generator((element, index) => {
|
|
20
|
+
accept(element, index);
|
|
21
|
+
count++;
|
|
22
|
+
}, interrupt);
|
|
23
|
+
let otherGenerator = Reflect.has(other, "generator") ? Reflect.get(other, "generator") : () => { };
|
|
24
|
+
otherGenerator((element, index) => {
|
|
25
|
+
accept(element, index + count);
|
|
26
|
+
}, interrupt);
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
throw new Error("Uncaught error on concatenation.");
|
|
30
|
+
}
|
|
25
31
|
});
|
|
26
32
|
}
|
|
27
33
|
if (isIterable(other)) {
|
|
28
34
|
return new Semantic((accept, interrupt) => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
try {
|
|
36
|
+
let count = 0n;
|
|
37
|
+
this.generator((element, index) => {
|
|
38
|
+
accept(element, index);
|
|
39
|
+
count++;
|
|
40
|
+
}, interrupt);
|
|
41
|
+
for (let element of other) {
|
|
42
|
+
accept(element, count);
|
|
43
|
+
count++;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
throw new Error("Uncaught error on concatenation.");
|
|
37
48
|
}
|
|
38
49
|
});
|
|
39
50
|
}
|
|
@@ -42,39 +53,54 @@ export class Semantic {
|
|
|
42
53
|
distinct(comparator) {
|
|
43
54
|
if (validate(comparator)) {
|
|
44
55
|
return new Semantic((accept, interrupt) => {
|
|
45
|
-
|
|
56
|
+
try {
|
|
57
|
+
let array = [];
|
|
58
|
+
this.generator((element, index) => {
|
|
59
|
+
if (!array.some((e) => comparator(e, element))) {
|
|
60
|
+
array.push(element);
|
|
61
|
+
accept(element, index);
|
|
62
|
+
}
|
|
63
|
+
}, interrupt);
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
throw new Error("Uncaught error on distinct.");
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
return new Semantic((accept, interrupt) => {
|
|
71
|
+
try {
|
|
72
|
+
let set = new Set();
|
|
46
73
|
this.generator((element, index) => {
|
|
47
|
-
if (!
|
|
48
|
-
|
|
74
|
+
if (!set.has(element)) {
|
|
75
|
+
set.add(element);
|
|
49
76
|
accept(element, index);
|
|
50
77
|
}
|
|
51
78
|
}, interrupt);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
this.generator((element, index) => {
|
|
57
|
-
if (!set.has(element)) {
|
|
58
|
-
set.add(element);
|
|
59
|
-
accept(element, index);
|
|
60
|
-
}
|
|
61
|
-
}, interrupt);
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
throw new Error("Uncaught error on distinct.");
|
|
82
|
+
}
|
|
62
83
|
});
|
|
63
84
|
}
|
|
64
85
|
dropWhile(predicate) {
|
|
65
86
|
if (isFunction(predicate)) {
|
|
66
87
|
return new Semantic((accept, interrupt) => {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
if (
|
|
71
|
-
|
|
72
|
-
|
|
88
|
+
try {
|
|
89
|
+
let dropping = true;
|
|
90
|
+
this.generator((element, index) => {
|
|
91
|
+
if (dropping) {
|
|
92
|
+
if (!predicate(element)) {
|
|
93
|
+
dropping = false;
|
|
94
|
+
accept(element, index);
|
|
95
|
+
}
|
|
96
|
+
return;
|
|
73
97
|
}
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
98
|
+
accept(element, index);
|
|
99
|
+
}, interrupt);
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
throw new Error("Uncaught error on dropWhile.");
|
|
103
|
+
}
|
|
78
104
|
});
|
|
79
105
|
}
|
|
80
106
|
throw new TypeError("Invalid arguments.");
|
|
@@ -82,11 +108,16 @@ export class Semantic {
|
|
|
82
108
|
filter(predicate) {
|
|
83
109
|
if (isFunction(predicate)) {
|
|
84
110
|
return new Semantic((accept, interrupt) => {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
111
|
+
try {
|
|
112
|
+
this.generator((element, index) => {
|
|
113
|
+
if (predicate(element)) {
|
|
114
|
+
accept(element, index);
|
|
115
|
+
}
|
|
116
|
+
}, interrupt);
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
throw new Error("Uncaught error on filter.");
|
|
120
|
+
}
|
|
90
121
|
});
|
|
91
122
|
}
|
|
92
123
|
throw new TypeError("Invalid arguments.");
|
|
@@ -94,25 +125,30 @@ export class Semantic {
|
|
|
94
125
|
flat(mapper) {
|
|
95
126
|
if (isFunction(mapper)) {
|
|
96
127
|
return new Semantic((accept, interrupt) => {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
128
|
+
try {
|
|
129
|
+
let count = 0n;
|
|
130
|
+
let stop = false;
|
|
131
|
+
this.generator((element) => {
|
|
132
|
+
let result = mapper(element);
|
|
133
|
+
if (isIterable(result)) {
|
|
134
|
+
for (let subElement of result) {
|
|
135
|
+
accept(subElement, count);
|
|
136
|
+
stop = stop || interrupt(subElement, count);
|
|
137
|
+
count++;
|
|
138
|
+
}
|
|
106
139
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
count
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
140
|
+
else if (isSemantic(result)) {
|
|
141
|
+
result.generator((subElement) => {
|
|
142
|
+
accept(subElement, count);
|
|
143
|
+
stop = stop || interrupt(subElement, count);
|
|
144
|
+
count++;
|
|
145
|
+
}, (element) => interrupt(element, count) || stop);
|
|
146
|
+
}
|
|
147
|
+
}, (element) => interrupt(element, count) || stop);
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
throw new Error("Uncaught error on flat.");
|
|
151
|
+
}
|
|
116
152
|
});
|
|
117
153
|
}
|
|
118
154
|
throw new TypeError("Invalid arguments.");
|
|
@@ -120,25 +156,30 @@ export class Semantic {
|
|
|
120
156
|
flatMap(mapper) {
|
|
121
157
|
if (isFunction(mapper)) {
|
|
122
158
|
return new Semantic((accept, interrupt) => {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
159
|
+
try {
|
|
160
|
+
let count = 0n;
|
|
161
|
+
let stop = false;
|
|
162
|
+
this.generator((element) => {
|
|
163
|
+
let result = mapper(element);
|
|
164
|
+
if (isIterable(result)) {
|
|
165
|
+
for (let subElement of result) {
|
|
166
|
+
accept(subElement, count);
|
|
167
|
+
stop = stop || interrupt(subElement, count);
|
|
168
|
+
count++;
|
|
169
|
+
}
|
|
132
170
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
count
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
171
|
+
else if (isSemantic(result)) {
|
|
172
|
+
result.generator((subElement) => {
|
|
173
|
+
accept(subElement, count);
|
|
174
|
+
stop = stop || interrupt(subElement, count);
|
|
175
|
+
count++;
|
|
176
|
+
}, (element) => interrupt(element, count) || stop);
|
|
177
|
+
}
|
|
178
|
+
}, () => stop);
|
|
179
|
+
}
|
|
180
|
+
catch (error) {
|
|
181
|
+
throw new Error("Uncaught error on flatMap.");
|
|
182
|
+
}
|
|
142
183
|
});
|
|
143
184
|
}
|
|
144
185
|
throw new TypeError("Invalid arguments.");
|
|
@@ -147,25 +188,35 @@ export class Semantic {
|
|
|
147
188
|
if (isNumber(n)) {
|
|
148
189
|
let limit = BigInt(n);
|
|
149
190
|
return new Semantic((accept, interrupt) => {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
191
|
+
try {
|
|
192
|
+
let count = 0n;
|
|
193
|
+
this.generator((element, index) => {
|
|
194
|
+
if (count < limit) {
|
|
195
|
+
accept(element, index);
|
|
196
|
+
count++;
|
|
197
|
+
}
|
|
198
|
+
}, (element) => interrupt(element, count) || count >= limit);
|
|
199
|
+
}
|
|
200
|
+
catch (error) {
|
|
201
|
+
throw new Error("Uncaught error on limit.");
|
|
202
|
+
}
|
|
157
203
|
});
|
|
158
204
|
}
|
|
159
205
|
if (isBigInt(n)) {
|
|
160
206
|
let limit = n;
|
|
161
207
|
return new Semantic((accept, interrupt) => {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
208
|
+
try {
|
|
209
|
+
let count = 0n;
|
|
210
|
+
this.generator((element, index) => {
|
|
211
|
+
if (count < limit) {
|
|
212
|
+
accept(element, index);
|
|
213
|
+
count++;
|
|
214
|
+
}
|
|
215
|
+
}, (element) => interrupt(element, count) || count >= limit);
|
|
216
|
+
}
|
|
217
|
+
catch (error) {
|
|
218
|
+
throw new Error("Uncaught error on limit.");
|
|
219
|
+
}
|
|
169
220
|
});
|
|
170
221
|
}
|
|
171
222
|
throw new TypeError("Invalid arguments.");
|
|
@@ -173,12 +224,17 @@ export class Semantic {
|
|
|
173
224
|
map(mapper) {
|
|
174
225
|
if (isFunction(mapper)) {
|
|
175
226
|
return new Semantic((accept, interrupt) => {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
227
|
+
try {
|
|
228
|
+
let stop = false;
|
|
229
|
+
this.generator((element, index) => {
|
|
230
|
+
let resolved = mapper(element);
|
|
231
|
+
accept(resolved, index);
|
|
232
|
+
stop = stop || interrupt(resolved, index);
|
|
233
|
+
}, () => stop);
|
|
234
|
+
}
|
|
235
|
+
catch (error) {
|
|
236
|
+
throw new Error("Uncaught error on map.");
|
|
237
|
+
}
|
|
182
238
|
});
|
|
183
239
|
}
|
|
184
240
|
throw new TypeError("Invalid arguments.");
|
|
@@ -186,10 +242,15 @@ export class Semantic {
|
|
|
186
242
|
peek(consumer) {
|
|
187
243
|
if (isFunction(consumer)) {
|
|
188
244
|
return new Semantic((accept, interrupt) => {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
245
|
+
try {
|
|
246
|
+
this.generator((element, index) => {
|
|
247
|
+
accept(element, index);
|
|
248
|
+
consumer(element, index);
|
|
249
|
+
}, interrupt);
|
|
250
|
+
}
|
|
251
|
+
catch (error) {
|
|
252
|
+
throw new Error("Uncaught error on peek.");
|
|
253
|
+
}
|
|
193
254
|
});
|
|
194
255
|
}
|
|
195
256
|
throw new TypeError("Invalid arguments.");
|
|
@@ -197,155 +258,244 @@ export class Semantic {
|
|
|
197
258
|
redirect(redirector) {
|
|
198
259
|
if (isFunction(redirector)) {
|
|
199
260
|
return new Semantic((accept, interrupt) => {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
261
|
+
try {
|
|
262
|
+
this.generator((element, index) => {
|
|
263
|
+
accept(element, redirector(element, index));
|
|
264
|
+
}, interrupt);
|
|
265
|
+
}
|
|
266
|
+
catch (error) {
|
|
267
|
+
throw new Error("Uncaught error on redirect.");
|
|
268
|
+
}
|
|
203
269
|
});
|
|
204
270
|
}
|
|
205
271
|
throw new TypeError("Invalid arguments.");
|
|
206
272
|
}
|
|
207
273
|
reverse() {
|
|
208
274
|
return new Semantic((accept, interrupt) => {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
275
|
+
try {
|
|
276
|
+
this.generator((element, index) => {
|
|
277
|
+
accept(element, -index);
|
|
278
|
+
}, interrupt);
|
|
279
|
+
}
|
|
280
|
+
catch (error) {
|
|
281
|
+
throw new Error("Uncaught error on reverse.");
|
|
282
|
+
}
|
|
212
283
|
});
|
|
213
284
|
}
|
|
214
285
|
shuffle(mapper) {
|
|
215
286
|
if (isFunction(mapper)) {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
287
|
+
try {
|
|
288
|
+
return new Semantic((accept, interrupt) => {
|
|
289
|
+
this.generator((element, index) => {
|
|
290
|
+
accept(element, mapper(element, index));
|
|
291
|
+
}, interrupt);
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
catch (error) {
|
|
295
|
+
throw new Error("Uncaught error on shuffle.");
|
|
296
|
+
}
|
|
221
297
|
}
|
|
222
298
|
return new Semantic((accept, interrupt) => {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
299
|
+
try {
|
|
300
|
+
this.generator((element, index) => {
|
|
301
|
+
accept(element, useRandom(index));
|
|
302
|
+
}, interrupt);
|
|
303
|
+
}
|
|
304
|
+
catch (error) {
|
|
305
|
+
throw new Error("Uncaught error on shuffle.");
|
|
306
|
+
}
|
|
226
307
|
});
|
|
227
308
|
}
|
|
228
309
|
skip(n) {
|
|
229
310
|
if (isNumber(n)) {
|
|
230
311
|
return new Semantic((accept, interrupt) => {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
count
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
312
|
+
try {
|
|
313
|
+
let count = 0n;
|
|
314
|
+
let limit = BigInt(n);
|
|
315
|
+
this.generator((element, index) => {
|
|
316
|
+
if (count < limit) {
|
|
317
|
+
count++;
|
|
318
|
+
}
|
|
319
|
+
else {
|
|
320
|
+
accept(element, index);
|
|
321
|
+
}
|
|
322
|
+
}, interrupt);
|
|
323
|
+
}
|
|
324
|
+
catch (error) {
|
|
325
|
+
throw new Error("Uncaught error on skip.");
|
|
326
|
+
}
|
|
241
327
|
});
|
|
242
328
|
}
|
|
243
329
|
if (isBigInt(n)) {
|
|
244
330
|
return new Semantic((accept, interrupt) => {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
count
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
331
|
+
try {
|
|
332
|
+
let count = 0n;
|
|
333
|
+
this.generator((element, index) => {
|
|
334
|
+
if (count < n) {
|
|
335
|
+
count++;
|
|
336
|
+
}
|
|
337
|
+
else {
|
|
338
|
+
accept(element, index);
|
|
339
|
+
}
|
|
340
|
+
}, interrupt);
|
|
341
|
+
}
|
|
342
|
+
catch (error) {
|
|
343
|
+
throw new Error("Uncaught error on skip.");
|
|
344
|
+
}
|
|
254
345
|
});
|
|
255
346
|
}
|
|
256
347
|
throw new TypeError("Invalid arguments.");
|
|
257
348
|
}
|
|
258
349
|
sorted(comparator) {
|
|
259
350
|
if (isFunction(comparator)) {
|
|
260
|
-
|
|
351
|
+
try {
|
|
352
|
+
return new OrderedCollectable(this.generator, comparator);
|
|
353
|
+
}
|
|
354
|
+
catch (error) {
|
|
355
|
+
throw new Error("Uncaught error on sorted.");
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
try {
|
|
359
|
+
return new OrderedCollectable(this.generator, (a, b) => useCompare(a, b));
|
|
360
|
+
}
|
|
361
|
+
catch (error) {
|
|
362
|
+
throw new Error("Uncaught error on sorted.");
|
|
261
363
|
}
|
|
262
|
-
return new OrderedCollectable(this.generator, (a, b) => useCompare(a, b));
|
|
263
364
|
}
|
|
264
365
|
sub(start, end) {
|
|
265
366
|
return new Semantic((accept, interrupt) => {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
count
|
|
270
|
-
|
|
271
|
-
|
|
367
|
+
try {
|
|
368
|
+
let count = 0n;
|
|
369
|
+
this.generator((element, index) => {
|
|
370
|
+
if (count < end) {
|
|
371
|
+
count++;
|
|
372
|
+
if (count >= start) {
|
|
373
|
+
accept(element, index);
|
|
374
|
+
}
|
|
272
375
|
}
|
|
273
|
-
}
|
|
274
|
-
}
|
|
376
|
+
}, interrupt);
|
|
377
|
+
}
|
|
378
|
+
catch (error) {
|
|
379
|
+
throw new Error("Uncaught error on sub.");
|
|
380
|
+
}
|
|
275
381
|
});
|
|
276
382
|
}
|
|
277
383
|
takeWhile(predicate) {
|
|
278
384
|
return new Semantic((accept, interrupt) => {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
385
|
+
try {
|
|
386
|
+
this.generator((element, index) => {
|
|
387
|
+
if (!predicate(element)) {
|
|
388
|
+
interrupt(element, index);
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
accept(element, index);
|
|
392
|
+
}, interrupt);
|
|
393
|
+
}
|
|
394
|
+
catch (error) {
|
|
395
|
+
throw new Error("Uncaught error on takeWhile.");
|
|
396
|
+
}
|
|
286
397
|
});
|
|
287
398
|
}
|
|
288
399
|
toCollectable(mapper) {
|
|
289
400
|
if (isFunction(mapper)) {
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
401
|
+
try {
|
|
402
|
+
let collectable = mapper(this.generator);
|
|
403
|
+
if (isCollectable(collectable)) {
|
|
404
|
+
return collectable;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
catch (error) {
|
|
408
|
+
throw new Error("Uncaught error on toCollectable.");
|
|
293
409
|
}
|
|
294
410
|
}
|
|
295
|
-
|
|
411
|
+
try {
|
|
412
|
+
return new UnorderedCollectable(this.generator);
|
|
413
|
+
}
|
|
414
|
+
catch (error) {
|
|
415
|
+
throw new Error("Uncaught error on toCollectable.");
|
|
416
|
+
}
|
|
296
417
|
}
|
|
297
418
|
toBigintStatistics() {
|
|
298
|
-
|
|
419
|
+
try {
|
|
420
|
+
return new BigIntStatistics(this.generator);
|
|
421
|
+
}
|
|
422
|
+
catch (error) {
|
|
423
|
+
throw new Error("Uncaught error on toBigintStatistics.");
|
|
424
|
+
}
|
|
299
425
|
}
|
|
300
426
|
toNumericStatistics() {
|
|
301
|
-
|
|
427
|
+
try {
|
|
428
|
+
return new NumericStatistics(this.generator);
|
|
429
|
+
}
|
|
430
|
+
catch (error) {
|
|
431
|
+
throw new Error("Uncaught error on toNumericStatistics.");
|
|
432
|
+
}
|
|
302
433
|
}
|
|
303
434
|
toOrdered() {
|
|
304
|
-
|
|
435
|
+
try {
|
|
436
|
+
return new OrderedCollectable(this.generator);
|
|
437
|
+
}
|
|
438
|
+
catch (error) {
|
|
439
|
+
throw new Error("Uncaught error on toOrdered.");
|
|
440
|
+
}
|
|
305
441
|
}
|
|
306
442
|
toUnordered() {
|
|
307
|
-
|
|
443
|
+
try {
|
|
444
|
+
return new UnorderedCollectable(this.generator);
|
|
445
|
+
}
|
|
446
|
+
catch (error) {
|
|
447
|
+
throw new Error("Uncaught error on toUnordered.");
|
|
448
|
+
}
|
|
308
449
|
}
|
|
309
450
|
toWindow() {
|
|
310
|
-
|
|
451
|
+
try {
|
|
452
|
+
return new WindowCollectable(this.generator);
|
|
453
|
+
}
|
|
454
|
+
catch (error) {
|
|
455
|
+
throw new Error("Uncaught error on toWindow.");
|
|
456
|
+
}
|
|
311
457
|
}
|
|
312
458
|
translate(argument1) {
|
|
313
459
|
if (isNumber(argument1)) {
|
|
314
460
|
let offset = argument1;
|
|
315
461
|
return new Semantic((accept, interrupt) => {
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
462
|
+
try {
|
|
463
|
+
this.generator((element, index) => {
|
|
464
|
+
accept(element, index + BigInt(offset));
|
|
465
|
+
}, interrupt);
|
|
466
|
+
}
|
|
467
|
+
catch (error) {
|
|
468
|
+
throw new Error("Uncaught error on translate.");
|
|
469
|
+
}
|
|
319
470
|
});
|
|
320
471
|
}
|
|
321
472
|
else if (isBigInt(argument1)) {
|
|
322
473
|
let offset = argument1;
|
|
323
474
|
return new Semantic((accept, interrupt) => {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
475
|
+
try {
|
|
476
|
+
this.generator((element, index) => {
|
|
477
|
+
accept(element, index + offset);
|
|
478
|
+
}, interrupt);
|
|
479
|
+
}
|
|
480
|
+
catch (error) {
|
|
481
|
+
throw new Error("Uncaught error on translate.");
|
|
482
|
+
}
|
|
327
483
|
});
|
|
328
484
|
}
|
|
329
485
|
else if (isFunction(argument1)) {
|
|
330
486
|
let translator = argument1;
|
|
331
487
|
return new Semantic((accept, interrupt) => {
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
488
|
+
try {
|
|
489
|
+
this.generator((element, index) => {
|
|
490
|
+
accept(element, index + translator(element, index));
|
|
491
|
+
}, interrupt);
|
|
492
|
+
}
|
|
493
|
+
catch (error) {
|
|
494
|
+
throw new Error("Uncaught error on translate.");
|
|
495
|
+
}
|
|
335
496
|
});
|
|
336
497
|
}
|
|
337
498
|
throw new TypeError("Invalid arguments.");
|
|
338
499
|
}
|
|
339
500
|
}
|
|
340
501
|
;
|
|
341
|
-
;
|
|
342
|
-
export let useTransform = (generator, mapper) => {
|
|
343
|
-
return (accept, interrupt) => {
|
|
344
|
-
generator((element, index) => {
|
|
345
|
-
let resolved = mapper(element, index);
|
|
346
|
-
accept(resolved, index);
|
|
347
|
-
}, (element, index) => {
|
|
348
|
-
return interrupt(mapper(element, index), index);
|
|
349
|
-
});
|
|
350
|
-
};
|
|
351
|
-
};
|