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