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