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