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/collectable.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { Collector, useAllMatch, useAnyMatch, useCollect, useCount, useError, useFindAny, useFindFirst, useFindLast, useForEach, useGroup, useGroupBy, useJoin, useLog, useNoneMatch, usePartition, useReduce, useToArray, useToMap, useToSet, useWrite } from "./collector";
|
|
2
|
-
import {
|
|
3
|
-
import { isBigInt, isCollector, isFunction, isIterable, isObject, isString } from "./guard";
|
|
1
|
+
import { Collector, useAllMatch, useAnyMatch, useCollect, useCount, useError, useFindAny, useFindFirst, useFindLast, useFindMaximum, useFindMinimum, useForEach, useGroup, useGroupBy, useJoin, useLog, useNoneMatch, usePartition, usePartitionBy, useReduce, useToArray, useToAsyncGeneratorFunction, useToGeneratorFunction, useToMap, useToSet, useWrite } from "./collector";
|
|
2
|
+
import { isBigInt, isCollector, isFunction, isObject, isString } from "./guard";
|
|
4
3
|
import { useCompare } from "./hook";
|
|
5
4
|
import { Optional } from "./optional";
|
|
6
5
|
import { Semantic } from "./semantic";
|
|
7
|
-
import { CollectableSymbol, OrderedCollectableSymbol, UnorderedCollectableSymbol
|
|
6
|
+
import { CollectableSymbol, OrderedCollectableSymbol, UnorderedCollectableSymbol } from "./symbol";
|
|
8
7
|
import { invalidate, validate } from "./utility";
|
|
9
8
|
export class Collectable {
|
|
10
9
|
Collectable = CollectableSymbol;
|
|
@@ -12,7 +11,12 @@ export class Collectable {
|
|
|
12
11
|
}
|
|
13
12
|
anyMatch(predicate) {
|
|
14
13
|
if (isFunction(predicate)) {
|
|
15
|
-
|
|
14
|
+
try {
|
|
15
|
+
return useAnyMatch(predicate).collect(this);
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
throw new Error("Uncaught error on anyMatch.");
|
|
19
|
+
}
|
|
16
20
|
}
|
|
17
21
|
throw new TypeError("Predicate must be a function.");
|
|
18
22
|
}
|
|
@@ -20,43 +24,63 @@ export class Collectable {
|
|
|
20
24
|
return useAllMatch(predicate).collect(this);
|
|
21
25
|
}
|
|
22
26
|
collect(argument1, argument2, argument3, argument4) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
27
|
+
try {
|
|
28
|
+
if (isCollector(argument1)) {
|
|
29
|
+
let collector = argument1;
|
|
30
|
+
return collector.collect(this);
|
|
31
|
+
}
|
|
32
|
+
if (isFunction(argument1) && isFunction(argument2) && isFunction(argument3)) {
|
|
33
|
+
let identity = argument1;
|
|
34
|
+
let accumulator = argument2;
|
|
35
|
+
let finisher = argument3;
|
|
36
|
+
return useCollect(identity, accumulator, finisher).collect(this);
|
|
37
|
+
}
|
|
38
|
+
if (isFunction(argument1) && isFunction(argument2) && isFunction(argument3) && isFunction(argument4)) {
|
|
39
|
+
let identity = argument1;
|
|
40
|
+
let interrupt = argument2;
|
|
41
|
+
let accumulator = argument3;
|
|
42
|
+
let finisher = argument4;
|
|
43
|
+
return useCollect(identity, interrupt, accumulator, finisher).collect(this);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
throw new Error("Uncaught error on collect.");
|
|
39
48
|
}
|
|
40
49
|
throw new TypeError("Invalid arguments.");
|
|
41
50
|
}
|
|
42
51
|
count() {
|
|
43
|
-
return useCount().collect(this);
|
|
52
|
+
return useCount().collect(this.source());
|
|
44
53
|
}
|
|
45
54
|
error(argument1, argument2, argument3) {
|
|
46
55
|
if (invalidate(argument1) && invalidate(argument2) && invalidate(argument3)) {
|
|
47
|
-
|
|
56
|
+
try {
|
|
57
|
+
useError().collect(this.source());
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
throw new Error("Uncaught error on error.");
|
|
61
|
+
}
|
|
48
62
|
}
|
|
49
63
|
else if (isFunction(argument1) && invalidate(argument2) && invalidate(argument3)) {
|
|
50
|
-
|
|
51
|
-
|
|
64
|
+
try {
|
|
65
|
+
let accumulator = argument1;
|
|
66
|
+
useError(accumulator).collect(this.source());
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
throw new Error("Uncaught error on error.");
|
|
70
|
+
}
|
|
52
71
|
}
|
|
53
72
|
else if (isString(argument1) && isFunction(argument2) && isString(argument3)) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
73
|
+
try {
|
|
74
|
+
let prefix = argument1;
|
|
75
|
+
let accumulator = argument2;
|
|
76
|
+
let suffix = argument3;
|
|
77
|
+
useError(prefix, accumulator, suffix).collect(this.source());
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
throw new Error("Uncaught error on error.");
|
|
81
|
+
}
|
|
58
82
|
}
|
|
59
|
-
{
|
|
83
|
+
else {
|
|
60
84
|
throw new TypeError("Invalid arguments.");
|
|
61
85
|
}
|
|
62
86
|
}
|
|
@@ -64,17 +88,55 @@ export class Collectable {
|
|
|
64
88
|
return this.count() === 0n;
|
|
65
89
|
}
|
|
66
90
|
findAny() {
|
|
67
|
-
|
|
91
|
+
try {
|
|
92
|
+
return useFindAny().collect(this.source());
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
throw new Error("Uncaught error on findAny.");
|
|
96
|
+
}
|
|
68
97
|
}
|
|
69
98
|
findFirst() {
|
|
70
|
-
|
|
99
|
+
try {
|
|
100
|
+
return useFindFirst().collect(this.source());
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
throw new Error("Uncaught error on findFirst.");
|
|
104
|
+
}
|
|
71
105
|
}
|
|
72
106
|
findLast() {
|
|
73
|
-
|
|
107
|
+
try {
|
|
108
|
+
return useFindLast().collect(this.source());
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
throw new Error("Uncaught error on findLast.");
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
findMaximum(argument1) {
|
|
115
|
+
try {
|
|
116
|
+
let comparator = isFunction(argument1) ? argument1 : useCompare;
|
|
117
|
+
return useFindMaximum(comparator).collect(this.source());
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
throw new Error("Uncaught error on findMaximum.");
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
findMinimum(argument1) {
|
|
124
|
+
try {
|
|
125
|
+
let comparator = isFunction(argument1) ? argument1 : useCompare;
|
|
126
|
+
return useFindMinimum(comparator).collect(this.source());
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
throw new Error("Uncaught error on findMinimum.");
|
|
130
|
+
}
|
|
74
131
|
}
|
|
75
132
|
forEach(action) {
|
|
76
133
|
if (isFunction(action)) {
|
|
77
|
-
|
|
134
|
+
try {
|
|
135
|
+
useForEach(action).collect(this);
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
throw new Error("Uncaught error on forEach.");
|
|
139
|
+
}
|
|
78
140
|
}
|
|
79
141
|
else {
|
|
80
142
|
throw new TypeError("Action must be a function.");
|
|
@@ -82,97 +144,162 @@ export class Collectable {
|
|
|
82
144
|
}
|
|
83
145
|
group(classifier) {
|
|
84
146
|
if (isFunction(classifier)) {
|
|
85
|
-
|
|
147
|
+
try {
|
|
148
|
+
return useGroup(classifier).collect(this.source());
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
throw new Error("Uncaught error on group.");
|
|
152
|
+
}
|
|
86
153
|
}
|
|
87
154
|
throw new TypeError("Classifier must be a function.");
|
|
88
155
|
}
|
|
89
156
|
groupBy(keyExtractor, valueExtractor) {
|
|
90
157
|
if (isFunction(keyExtractor) && isFunction(valueExtractor)) {
|
|
91
|
-
|
|
158
|
+
try {
|
|
159
|
+
return useGroupBy(keyExtractor, valueExtractor).collect(this.source());
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
throw new Error("Uncaught error on groupBy.");
|
|
163
|
+
}
|
|
92
164
|
}
|
|
93
165
|
throw new TypeError("Key and value extractors must be functions.");
|
|
94
166
|
}
|
|
95
167
|
join(argument1, argument2, argument3) {
|
|
96
168
|
if (invalidate(argument1) && invalidate(argument2) && invalidate(argument3)) {
|
|
97
|
-
|
|
169
|
+
try {
|
|
170
|
+
return useJoin().collect(this.source());
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
throw new Error("Uncaught error on join.");
|
|
174
|
+
}
|
|
98
175
|
}
|
|
99
|
-
if (isString(argument1) && invalidate(argument2) && invalidate(argument3)) {
|
|
100
|
-
|
|
101
|
-
|
|
176
|
+
else if (isString(argument1) && invalidate(argument2) && invalidate(argument3)) {
|
|
177
|
+
try {
|
|
178
|
+
let delimiter = argument1;
|
|
179
|
+
return useJoin(delimiter).collect(this.source());
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
throw new Error("Uncaught error on join.");
|
|
183
|
+
}
|
|
102
184
|
}
|
|
103
|
-
if (isString(argument1) && isFunction(argument2) && isString(argument3)) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
185
|
+
else if (isString(argument1) && isFunction(argument2) && isString(argument3)) {
|
|
186
|
+
try {
|
|
187
|
+
let prefix = argument1;
|
|
188
|
+
let accumulator = argument2;
|
|
189
|
+
let suffix = argument3;
|
|
190
|
+
return useJoin(prefix, accumulator, suffix).collect(this.source());
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
throw new Error("Uncaught error on join.");
|
|
194
|
+
}
|
|
108
195
|
}
|
|
109
|
-
if (isString(argument1) && isString(argument2) && isString(argument3)) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
196
|
+
else if (isString(argument1) && isString(argument2) && isString(argument3)) {
|
|
197
|
+
try {
|
|
198
|
+
let prefix = argument1;
|
|
199
|
+
let delimiter = argument2;
|
|
200
|
+
let suffix = argument3;
|
|
201
|
+
return useJoin(prefix, delimiter, suffix).collect(this.source());
|
|
202
|
+
}
|
|
203
|
+
catch (error) {
|
|
204
|
+
throw new Error("Uncaught error on join.");
|
|
205
|
+
}
|
|
114
206
|
}
|
|
115
207
|
throw new TypeError("Invalid arguments.");
|
|
116
208
|
}
|
|
117
209
|
log(argument1, argument2, argument3) {
|
|
118
|
-
if (
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
210
|
+
if (isFunction(argument1) && invalidate(argument2) && invalidate(argument3)) {
|
|
211
|
+
try {
|
|
212
|
+
let accumulator = argument1;
|
|
213
|
+
useLog(accumulator).collect(this.source());
|
|
214
|
+
}
|
|
215
|
+
catch (error) {
|
|
216
|
+
throw new Error("Uncaught error on log.");
|
|
217
|
+
}
|
|
124
218
|
}
|
|
125
219
|
else if (isString(argument1) && isFunction(argument2) && isString(argument3)) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
220
|
+
try {
|
|
221
|
+
let prefix = argument1;
|
|
222
|
+
let accumulator = argument2;
|
|
223
|
+
let suffix = argument3;
|
|
224
|
+
useLog(prefix, accumulator, suffix).collect(this.source());
|
|
225
|
+
}
|
|
226
|
+
catch (error) {
|
|
227
|
+
throw new Error("Uncaught error on log.");
|
|
228
|
+
}
|
|
130
229
|
}
|
|
131
|
-
{
|
|
132
|
-
|
|
230
|
+
else {
|
|
231
|
+
try {
|
|
232
|
+
useLog().collect(this.source());
|
|
233
|
+
}
|
|
234
|
+
catch (error) {
|
|
235
|
+
throw new Error("Uncaught error on log.");
|
|
236
|
+
}
|
|
133
237
|
}
|
|
134
238
|
}
|
|
135
239
|
nonMatch(predicate) {
|
|
136
240
|
if (isFunction(predicate)) {
|
|
137
|
-
|
|
241
|
+
try {
|
|
242
|
+
return useNoneMatch(predicate).collect(this.source());
|
|
243
|
+
}
|
|
244
|
+
catch (error) {
|
|
245
|
+
throw new Error("Uncaught error on nonMatch.");
|
|
246
|
+
}
|
|
138
247
|
}
|
|
139
248
|
throw new TypeError("Predicate must be a function.");
|
|
140
249
|
}
|
|
141
250
|
partition(count) {
|
|
142
251
|
if (isBigInt(count)) {
|
|
143
|
-
|
|
252
|
+
try {
|
|
253
|
+
return usePartition(count).collect(this.source());
|
|
254
|
+
}
|
|
255
|
+
catch (error) {
|
|
256
|
+
throw new Error("Uncaught error on partition.");
|
|
257
|
+
}
|
|
144
258
|
}
|
|
145
259
|
throw new TypeError("Count must be a BigInt.");
|
|
146
260
|
}
|
|
147
261
|
partitionBy(classifier) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
return result;
|
|
159
|
-
});
|
|
262
|
+
if (isFunction(classifier)) {
|
|
263
|
+
try {
|
|
264
|
+
let collector = usePartitionBy(classifier);
|
|
265
|
+
return collector.collect(this.source());
|
|
266
|
+
}
|
|
267
|
+
catch (error) {
|
|
268
|
+
throw new Error("Uncaught error on partitionBy.");
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
throw new TypeError("Classifier must be a function.");
|
|
160
272
|
}
|
|
161
273
|
reduce(argument1, argument2, argument3) {
|
|
162
274
|
if (isFunction(argument1) && invalidate(argument2) && invalidate(argument3)) {
|
|
163
|
-
|
|
164
|
-
|
|
275
|
+
try {
|
|
276
|
+
let accumulator = argument1;
|
|
277
|
+
return useReduce(accumulator).collect(this.source());
|
|
278
|
+
}
|
|
279
|
+
catch (error) {
|
|
280
|
+
throw new Error("Uncaught error on reduce.");
|
|
281
|
+
}
|
|
165
282
|
}
|
|
166
283
|
else if (validate(argument1) && isFunction(argument2) && invalidate(argument3)) {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
284
|
+
try {
|
|
285
|
+
let identity = argument1;
|
|
286
|
+
let accumulator = argument2;
|
|
287
|
+
return useReduce(identity, accumulator).collect(this.source());
|
|
288
|
+
}
|
|
289
|
+
catch (error) {
|
|
290
|
+
throw new Error("Uncaught error on reduce.");
|
|
291
|
+
}
|
|
170
292
|
}
|
|
171
293
|
else if (validate(argument1) && isFunction(argument2) && isFunction(argument3)) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
294
|
+
try {
|
|
295
|
+
let identity = argument1;
|
|
296
|
+
let accumulator = argument2;
|
|
297
|
+
let finisher = argument3;
|
|
298
|
+
return useReduce(identity, accumulator, finisher).collect(this.source());
|
|
299
|
+
}
|
|
300
|
+
catch (error) {
|
|
301
|
+
throw new Error("Uncaught error on reduce.");
|
|
302
|
+
}
|
|
176
303
|
}
|
|
177
304
|
else {
|
|
178
305
|
throw new TypeError("Invalid arguments.");
|
|
@@ -180,34 +307,56 @@ export class Collectable {
|
|
|
180
307
|
}
|
|
181
308
|
semantic() {
|
|
182
309
|
let source = this.source();
|
|
183
|
-
if (
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
310
|
+
if (isFunction(source)) {
|
|
311
|
+
try {
|
|
312
|
+
return new Semantic(source);
|
|
313
|
+
}
|
|
314
|
+
catch (error) {
|
|
315
|
+
throw new Error("Uncaught error on semantic.");
|
|
316
|
+
}
|
|
188
317
|
}
|
|
189
318
|
else {
|
|
190
319
|
throw new TypeError("Invalid source.");
|
|
191
320
|
}
|
|
192
321
|
}
|
|
193
322
|
toArray() {
|
|
194
|
-
|
|
323
|
+
try {
|
|
324
|
+
return useToArray().collect(this.source());
|
|
325
|
+
}
|
|
326
|
+
catch (error) {
|
|
327
|
+
throw new Error("Uncaught error on toArray.");
|
|
328
|
+
}
|
|
195
329
|
}
|
|
196
330
|
toMap(keyExtractor, valueExtractor) {
|
|
197
|
-
|
|
331
|
+
try {
|
|
332
|
+
return useToMap(keyExtractor, valueExtractor).collect(this.source());
|
|
333
|
+
}
|
|
334
|
+
catch (error) {
|
|
335
|
+
throw new Error("Uncaught error on toMap.");
|
|
336
|
+
}
|
|
198
337
|
}
|
|
199
338
|
toSet() {
|
|
200
|
-
|
|
339
|
+
try {
|
|
340
|
+
return useToSet().collect(this.source());
|
|
341
|
+
}
|
|
342
|
+
catch (error) {
|
|
343
|
+
throw new Error("Uncaught error on toSet.");
|
|
344
|
+
}
|
|
201
345
|
}
|
|
202
346
|
write(argument1, argument2) {
|
|
203
347
|
if (isObject(argument1)) {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
348
|
+
try {
|
|
349
|
+
let stream = argument1;
|
|
350
|
+
if (isFunction(argument2)) {
|
|
351
|
+
let accumulator = argument2;
|
|
352
|
+
return useWrite(stream, accumulator).collect(this.source());
|
|
353
|
+
}
|
|
354
|
+
else {
|
|
355
|
+
return useWrite(stream).collect(this.source());
|
|
356
|
+
}
|
|
208
357
|
}
|
|
209
|
-
|
|
210
|
-
|
|
358
|
+
catch (error) {
|
|
359
|
+
throw new Error("Uncaught error on write.");
|
|
211
360
|
}
|
|
212
361
|
}
|
|
213
362
|
throw new TypeError("Invalid arguments.");
|
|
@@ -217,106 +366,109 @@ export class Collectable {
|
|
|
217
366
|
export class UnorderedCollectable extends Collectable {
|
|
218
367
|
UnorderedCollectable = UnorderedCollectableSymbol;
|
|
219
368
|
generator;
|
|
220
|
-
constructor(
|
|
369
|
+
constructor(argument1) {
|
|
221
370
|
super();
|
|
222
|
-
|
|
371
|
+
if (isFunction(argument1)) {
|
|
372
|
+
this.generator = argument1;
|
|
373
|
+
}
|
|
374
|
+
else {
|
|
375
|
+
throw new TypeError("Source must be an iterable or a generator function.");
|
|
376
|
+
}
|
|
223
377
|
}
|
|
224
378
|
source() {
|
|
225
379
|
return this.generator;
|
|
226
380
|
}
|
|
381
|
+
*[Symbol.iterator]() {
|
|
382
|
+
try {
|
|
383
|
+
let collector = useToGeneratorFunction();
|
|
384
|
+
yield* collector.collect(this.generator);
|
|
385
|
+
}
|
|
386
|
+
catch (error) {
|
|
387
|
+
throw new Error("Uncaught error on Generator.");
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
async *[Symbol.asyncIterator]() {
|
|
391
|
+
try {
|
|
392
|
+
let collector = useToAsyncGeneratorFunction();
|
|
393
|
+
yield* collector.collect(this.generator);
|
|
394
|
+
}
|
|
395
|
+
catch (error) {
|
|
396
|
+
throw new Error("Uncaught error on AsyncGenerator.");
|
|
397
|
+
}
|
|
398
|
+
}
|
|
227
399
|
}
|
|
228
400
|
;
|
|
229
401
|
export class OrderedCollectable extends Collectable {
|
|
230
402
|
OrderedCollectable = OrderedCollectableSymbol;
|
|
231
|
-
|
|
403
|
+
buffer;
|
|
232
404
|
constructor(argument1, argument2) {
|
|
233
405
|
super();
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
406
|
+
if (isFunction(argument1)) {
|
|
407
|
+
try {
|
|
408
|
+
if (isFunction(argument2)) {
|
|
409
|
+
let collector = useToArray();
|
|
410
|
+
this.buffer = collector.collect(argument1).sort(argument2).map((element, index) => {
|
|
411
|
+
return {
|
|
412
|
+
element: element,
|
|
413
|
+
index: BigInt(index)
|
|
414
|
+
};
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
else {
|
|
418
|
+
let collector = useToArray();
|
|
419
|
+
this.buffer = collector.collect(argument1).map((element, index) => {
|
|
420
|
+
return {
|
|
421
|
+
element: element,
|
|
422
|
+
index: BigInt(index)
|
|
423
|
+
};
|
|
424
|
+
}).sort((a, b) => {
|
|
425
|
+
return Number(a.index - b.index);
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
catch (error) {
|
|
430
|
+
throw new Error("Uncaught error on creating buffer.");
|
|
431
|
+
}
|
|
254
432
|
}
|
|
255
433
|
else {
|
|
256
|
-
throw new TypeError("
|
|
434
|
+
throw new TypeError("Source must be an iterable or a generator function.");
|
|
257
435
|
}
|
|
258
|
-
buffer.map((indexed, _index, array) => {
|
|
259
|
-
let length = BigInt(array.length);
|
|
260
|
-
return {
|
|
261
|
-
index: ((indexed.index % length) + length) % length,
|
|
262
|
-
value: indexed.value
|
|
263
|
-
};
|
|
264
|
-
}).sort((a, b) => {
|
|
265
|
-
if (isFunction(argument2)) {
|
|
266
|
-
let comparator = argument2;
|
|
267
|
-
return comparator(a.value, b.value);
|
|
268
|
-
}
|
|
269
|
-
else {
|
|
270
|
-
return useCompare(a.index, b.index);
|
|
271
|
-
}
|
|
272
|
-
}).forEach((indexed) => {
|
|
273
|
-
this.ordered.push(indexed);
|
|
274
|
-
});
|
|
275
436
|
}
|
|
276
|
-
|
|
277
|
-
|
|
437
|
+
*[Symbol.iterator]() {
|
|
438
|
+
try {
|
|
439
|
+
let collector = useToGeneratorFunction();
|
|
440
|
+
yield* collector.collect(this.source());
|
|
441
|
+
}
|
|
442
|
+
catch (error) {
|
|
443
|
+
throw new Error("Uncaught error on Generator.");
|
|
444
|
+
}
|
|
278
445
|
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
constructor(parameter, comparator) {
|
|
284
|
-
if (isIterable(parameter)) {
|
|
285
|
-
if (isFunction(comparator)) {
|
|
286
|
-
super(parameter, comparator);
|
|
287
|
-
}
|
|
288
|
-
else {
|
|
289
|
-
super(parameter);
|
|
290
|
-
}
|
|
446
|
+
async *[Symbol.asyncIterator]() {
|
|
447
|
+
try {
|
|
448
|
+
let collector = useToAsyncGeneratorFunction();
|
|
449
|
+
yield* collector.collect(this.source());
|
|
291
450
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
super(parameter, comparator);
|
|
295
|
-
}
|
|
296
|
-
else {
|
|
297
|
-
super(parameter);
|
|
298
|
-
}
|
|
451
|
+
catch (error) {
|
|
452
|
+
throw new Error("Uncaught error on AsyncGenerator.");
|
|
299
453
|
}
|
|
300
454
|
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
if (window.length > 0) {
|
|
310
|
-
windows.push(window);
|
|
455
|
+
source() {
|
|
456
|
+
try {
|
|
457
|
+
return (accept, interrupt) => {
|
|
458
|
+
for (let indexed of this.buffer) {
|
|
459
|
+
if (interrupt(indexed.element, indexed.index)) {
|
|
460
|
+
break;
|
|
461
|
+
}
|
|
462
|
+
accept(indexed.element, indexed.index);
|
|
311
463
|
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
catch (error) {
|
|
467
|
+
throw new Error("Uncaught error on creating source.");
|
|
315
468
|
}
|
|
316
|
-
throw new RangeError("Invalid arguments.");
|
|
317
469
|
}
|
|
318
|
-
|
|
319
|
-
return this.
|
|
470
|
+
isEmpty() {
|
|
471
|
+
return this.buffer.length === 0;
|
|
320
472
|
}
|
|
321
473
|
}
|
|
322
474
|
;
|