semantic-typescript 0.2.9 → 0.3.1
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.
Potentially problematic release.
This version of semantic-typescript might be problematic. Click here for more details.
- package/dist/collectable.d.ts +12 -7
- package/dist/collectable.js +80 -237
- package/dist/collector.d.ts +99 -1
- package/dist/collector.js +422 -1
- package/dist/factory.d.ts +6 -0
- package/dist/factory.js +23 -2
- package/dist/hook.d.ts +2 -2
- package/dist/hook.js +14 -2
- package/dist/semantic.d.ts +5 -0
- package/dist/semantic.js +13 -1
- package/package.json +3 -5
- package/readme.md +86 -32
package/dist/collectable.d.ts
CHANGED
|
@@ -17,6 +17,11 @@ export declare abstract class Collectable<E> {
|
|
|
17
17
|
collect<A, R>(identity: Supplier<A>, interruptor: BiPredicate<E, bigint>, accumulator: TriFunctional<A, E, bigint, A>, finisher: Functional<A, R>): R;
|
|
18
18
|
collect<A, R>(identity: Supplier<A>, interruptor: TriPredicate<E, bigint, A>, accumulator: TriFunctional<A, E, bigint, A>, finisher: Functional<A, R>): R;
|
|
19
19
|
count(): bigint;
|
|
20
|
+
error(): void;
|
|
21
|
+
error(accumulator: BiFunctional<string, E, string>): void;
|
|
22
|
+
error(accumulator: TriFunctional<string, E, bigint, string>): void;
|
|
23
|
+
error(prefix: string, accumulator: BiFunctional<string, E, string>, suffix: string): void;
|
|
24
|
+
error(prefix: string, accumulator: TriFunctional<string, E, bigint, string>, suffix: string): void;
|
|
20
25
|
isEmpty(): boolean;
|
|
21
26
|
findAny(): Optional<E>;
|
|
22
27
|
findFirst(): Optional<E>;
|
|
@@ -32,7 +37,7 @@ export declare abstract class Collectable<E> {
|
|
|
32
37
|
join(prefiex: string, accumulator: TriFunctional<string, E, bigint, string>, suffix: string): string;
|
|
33
38
|
log(): void;
|
|
34
39
|
log(accumulator: BiFunctional<string, E, string>): void;
|
|
35
|
-
log(accumulator:
|
|
40
|
+
log(accumulator: TriFunctional<string, E, bigint, string>): void;
|
|
36
41
|
log(prefix: string, accumulator: BiFunctional<string, E, string>, suffix: string): void;
|
|
37
42
|
log(prefix: string, accumulator: TriFunctional<string, E, bigint, string>, suffix: string): void;
|
|
38
43
|
nonMatch(predicate: Predicate<E>): boolean;
|
|
@@ -42,16 +47,16 @@ export declare abstract class Collectable<E> {
|
|
|
42
47
|
reduce(accumulator: TriFunctional<E, E, bigint, E>): Optional<E>;
|
|
43
48
|
reduce(identity: E, accumulator: BiFunctional<E, E, E>): E;
|
|
44
49
|
reduce(identity: E, accumulator: TriFunctional<E, E, bigint, E>): E;
|
|
45
|
-
reduce<R>(identity: R, accumulator: BiFunctional<R, E, R>, finisher:
|
|
46
|
-
reduce<R>(identity: R, accumulator: TriFunctional<R, E, bigint, R>, finisher:
|
|
50
|
+
reduce<R>(identity: R, accumulator: BiFunctional<R, E, R>, finisher: Functional<R, R>): R;
|
|
51
|
+
reduce<R>(identity: R, accumulator: TriFunctional<R, E, bigint, R>, finisher: Functional<R, R>): R;
|
|
47
52
|
semantic(): Semantic<E>;
|
|
48
|
-
|
|
53
|
+
abstract source(): Generator<E> | Iterable<E>;
|
|
49
54
|
toArray(): Array<E>;
|
|
50
55
|
toMap<K, V>(keyExtractor: Functional<E, K>, valueExtractor: Functional<E, V>): Map<K, V>;
|
|
51
56
|
toSet(): Set<E>;
|
|
52
|
-
write(stream: WritableStream<
|
|
53
|
-
write(stream: WritableStream<
|
|
54
|
-
write(stream: WritableStream<
|
|
57
|
+
write<S = string>(stream: WritableStream<S>): Collector<E, Promise<WritableStream<S>>, Promise<WritableStream<S>>>;
|
|
58
|
+
write<S = string>(stream: WritableStream<S>, accumulator: BiFunctional<WritableStream<S>, E, WritableStream<S>>): Collector<E, Promise<WritableStream<S>>, Promise<WritableStream<S>>>;
|
|
59
|
+
write<S = string>(stream: WritableStream<S>, accumulator: TriFunctional<WritableStream<S>, E, bigint, WritableStream<S>>): Collector<E, Promise<WritableStream<S>>, Promise<WritableStream<S>>>;
|
|
55
60
|
}
|
|
56
61
|
export declare class UnorderedCollectable<E> extends Collectable<E> {
|
|
57
62
|
protected readonly UnorderedCollectable: symbol;
|
package/dist/collectable.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Collector } from "./collector";
|
|
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
2
|
import { from } from "./factory";
|
|
3
|
-
import { isCollector, isFunction, isIterable, isObject, isString } from "./guard";
|
|
3
|
+
import { isBigInt, isCollector, isFunction, isIterable, isObject, isString } from "./guard";
|
|
4
4
|
import { useCompare } from "./hook";
|
|
5
5
|
import { Optional } from "./optional";
|
|
6
6
|
import { Semantic } from "./semantic";
|
|
@@ -11,226 +11,138 @@ export class Collectable {
|
|
|
11
11
|
constructor() {
|
|
12
12
|
}
|
|
13
13
|
anyMatch(predicate) {
|
|
14
|
-
|
|
15
|
-
return
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
}, (result, element) => {
|
|
19
|
-
return result || predicate(element);
|
|
20
|
-
}, (result) => {
|
|
21
|
-
return result;
|
|
22
|
-
});
|
|
14
|
+
if (isFunction(predicate)) {
|
|
15
|
+
return useAnyMatch(predicate).collect(this);
|
|
16
|
+
}
|
|
17
|
+
throw new TypeError("Predicate must be a function.");
|
|
23
18
|
}
|
|
24
19
|
allMatch(predicate) {
|
|
25
|
-
return
|
|
26
|
-
return true;
|
|
27
|
-
}, (_element, _index, accumulator) => {
|
|
28
|
-
return !accumulator;
|
|
29
|
-
}, (result, element) => {
|
|
30
|
-
return result && predicate(element);
|
|
31
|
-
}, (result) => {
|
|
32
|
-
return result;
|
|
33
|
-
});
|
|
20
|
+
return useAllMatch(predicate).collect(this);
|
|
34
21
|
}
|
|
35
22
|
collect(argument1, argument2, argument3, argument4) {
|
|
36
|
-
let source = this.source();
|
|
37
23
|
if (isCollector(argument1)) {
|
|
38
24
|
let collector = argument1;
|
|
39
|
-
return collector.collect(
|
|
25
|
+
return collector.collect(this);
|
|
40
26
|
}
|
|
41
27
|
if (isFunction(argument1) && isFunction(argument2) && isFunction(argument3)) {
|
|
42
28
|
let identity = argument1;
|
|
43
29
|
let accumulator = argument2;
|
|
44
30
|
let finisher = argument3;
|
|
45
|
-
|
|
46
|
-
return collector.collect(source);
|
|
31
|
+
return useCollect(identity, accumulator, finisher).collect(this);
|
|
47
32
|
}
|
|
48
33
|
if (isFunction(argument1) && isFunction(argument2) && isFunction(argument3) && isFunction(argument4)) {
|
|
49
34
|
let identity = argument1;
|
|
50
35
|
let interrupt = argument2;
|
|
51
36
|
let accumulator = argument3;
|
|
52
37
|
let finisher = argument4;
|
|
53
|
-
|
|
54
|
-
return collector.collect(source);
|
|
38
|
+
return useCollect(identity, interrupt, accumulator, finisher).collect(this);
|
|
55
39
|
}
|
|
56
40
|
throw new TypeError("Invalid arguments.");
|
|
57
41
|
}
|
|
58
42
|
count() {
|
|
59
|
-
return
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
43
|
+
return useCount().collect(this);
|
|
44
|
+
}
|
|
45
|
+
error(argument1, argument2, argument3) {
|
|
46
|
+
if (invalidate(argument1) && invalidate(argument2) && invalidate(argument3)) {
|
|
47
|
+
useError().collect(this);
|
|
48
|
+
}
|
|
49
|
+
else if (isFunction(argument1) && invalidate(argument2) && invalidate(argument3)) {
|
|
50
|
+
let accumulator = argument1;
|
|
51
|
+
useError(accumulator).collect(this);
|
|
52
|
+
}
|
|
53
|
+
else if (isString(argument1) && isFunction(argument2) && isString(argument3)) {
|
|
54
|
+
let prefix = argument1;
|
|
55
|
+
let accumulator = argument2;
|
|
56
|
+
let suffix = argument3;
|
|
57
|
+
useError(prefix, accumulator, suffix).collect(this);
|
|
58
|
+
}
|
|
59
|
+
{
|
|
60
|
+
throw new TypeError("Invalid arguments.");
|
|
61
|
+
}
|
|
66
62
|
}
|
|
67
63
|
isEmpty() {
|
|
68
64
|
return this.count() === 0n;
|
|
69
65
|
}
|
|
70
66
|
findAny() {
|
|
71
|
-
return
|
|
72
|
-
return Optional.empty();
|
|
73
|
-
}, (_element, _index, accumulator) => {
|
|
74
|
-
return accumulator.isPresent();
|
|
75
|
-
}, (result, element) => {
|
|
76
|
-
if (Math.random() < 0.5) {
|
|
77
|
-
return Optional.of(element);
|
|
78
|
-
}
|
|
79
|
-
return result;
|
|
80
|
-
}, (result) => {
|
|
81
|
-
return result;
|
|
82
|
-
});
|
|
67
|
+
return useFindAny().collect(this);
|
|
83
68
|
}
|
|
84
69
|
findFirst() {
|
|
85
|
-
return
|
|
86
|
-
return Optional.empty();
|
|
87
|
-
}, (_element, _index, accumulator) => {
|
|
88
|
-
return accumulator.isPresent();
|
|
89
|
-
}, (result, element) => {
|
|
90
|
-
return result.isPresent() ? result : Optional.of(element);
|
|
91
|
-
}, (result) => {
|
|
92
|
-
return result;
|
|
93
|
-
});
|
|
70
|
+
return useFindFirst().collect(this);
|
|
94
71
|
}
|
|
95
72
|
findLast() {
|
|
96
|
-
return
|
|
97
|
-
return Optional.empty();
|
|
98
|
-
}, () => {
|
|
99
|
-
return false;
|
|
100
|
-
}, (result, element) => {
|
|
101
|
-
return result.isPresent() ? result : Optional.of(element);
|
|
102
|
-
}, (result) => {
|
|
103
|
-
return result;
|
|
104
|
-
});
|
|
73
|
+
return useFindLast().collect(this);
|
|
105
74
|
}
|
|
106
75
|
forEach(action) {
|
|
107
76
|
if (isFunction(action)) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
return count + 1n;
|
|
113
|
-
}, (count) => {
|
|
114
|
-
return count;
|
|
115
|
-
});
|
|
77
|
+
useForEach(action).collect(this);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
throw new TypeError("Action must be a function.");
|
|
116
81
|
}
|
|
117
82
|
}
|
|
118
83
|
group(classifier) {
|
|
119
84
|
if (isFunction(classifier)) {
|
|
120
|
-
return
|
|
121
|
-
return new Map();
|
|
122
|
-
}, (map, element) => {
|
|
123
|
-
let key = classifier(element);
|
|
124
|
-
let raw = map.get(key);
|
|
125
|
-
let array = validate(raw) ? raw : [];
|
|
126
|
-
array.push(element);
|
|
127
|
-
map.set(key, array);
|
|
128
|
-
return map;
|
|
129
|
-
}, (map) => {
|
|
130
|
-
return map;
|
|
131
|
-
});
|
|
85
|
+
return useGroup(classifier).collect(this);
|
|
132
86
|
}
|
|
133
|
-
throw new TypeError("
|
|
87
|
+
throw new TypeError("Classifier must be a function.");
|
|
134
88
|
}
|
|
135
89
|
groupBy(keyExtractor, valueExtractor) {
|
|
136
|
-
|
|
137
|
-
return
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
let value = valueExtractor(element);
|
|
141
|
-
let group = (validate(map.get(key)) ? map.get(key) : []);
|
|
142
|
-
group.push(value);
|
|
143
|
-
map.set(key, group);
|
|
144
|
-
return map;
|
|
145
|
-
}, (map) => {
|
|
146
|
-
return map;
|
|
147
|
-
});
|
|
90
|
+
if (isFunction(keyExtractor) && isFunction(valueExtractor)) {
|
|
91
|
+
return useGroupBy(keyExtractor, valueExtractor).collect(this);
|
|
92
|
+
}
|
|
93
|
+
throw new TypeError("Key and value extractors must be functions.");
|
|
148
94
|
}
|
|
149
95
|
join(argument1, argument2, argument3) {
|
|
150
96
|
if (invalidate(argument1) && invalidate(argument2) && invalidate(argument3)) {
|
|
151
|
-
return
|
|
152
|
-
return "[";
|
|
153
|
-
}, (text, element) => {
|
|
154
|
-
return text + element + ",";
|
|
155
|
-
}, (text) => {
|
|
156
|
-
return text.substring(0, text.length - 1) + "]";
|
|
157
|
-
});
|
|
97
|
+
return useJoin().collect(this);
|
|
158
98
|
}
|
|
159
99
|
if (isString(argument1) && invalidate(argument2) && invalidate(argument3)) {
|
|
160
100
|
let delimiter = argument1;
|
|
161
|
-
return
|
|
162
|
-
return "[";
|
|
163
|
-
}, (text, element) => {
|
|
164
|
-
return text + element + delimiter;
|
|
165
|
-
}, (text) => {
|
|
166
|
-
return text.substring(0, text.length - 1) + "]";
|
|
167
|
-
});
|
|
101
|
+
return useJoin(delimiter).collect(this);
|
|
168
102
|
}
|
|
169
103
|
if (isString(argument1) && isFunction(argument2) && isString(argument3)) {
|
|
170
104
|
let prefix = argument1;
|
|
171
105
|
let accumulator = argument2;
|
|
172
106
|
let suffix = argument3;
|
|
173
|
-
return
|
|
174
|
-
return prefix;
|
|
175
|
-
}, (text, element, index) => {
|
|
176
|
-
return text + accumulator(text, element, index);
|
|
177
|
-
}, (text) => {
|
|
178
|
-
return text + suffix;
|
|
179
|
-
});
|
|
107
|
+
return useJoin(prefix, accumulator, suffix).collect(this);
|
|
180
108
|
}
|
|
181
109
|
if (isString(argument1) && isString(argument2) && isString(argument3)) {
|
|
182
110
|
let prefix = argument1;
|
|
183
111
|
let delimiter = argument2;
|
|
184
112
|
let suffix = argument3;
|
|
185
|
-
return
|
|
186
|
-
return prefix;
|
|
187
|
-
}, (text, element) => {
|
|
188
|
-
return text + element + delimiter;
|
|
189
|
-
}, (text) => {
|
|
190
|
-
return text + suffix;
|
|
191
|
-
});
|
|
113
|
+
return useJoin(prefix, delimiter, suffix).collect(this);
|
|
192
114
|
}
|
|
193
115
|
throw new TypeError("Invalid arguments.");
|
|
194
116
|
}
|
|
195
117
|
log(argument1, argument2, argument3) {
|
|
196
118
|
if (invalidate(argument1) && invalidate(argument2) && invalidate(argument3)) {
|
|
197
|
-
|
|
198
|
-
console.log(text);
|
|
119
|
+
useLog().collect(this);
|
|
199
120
|
}
|
|
200
121
|
else if (isFunction(argument1) && invalidate(argument2) && invalidate(argument3)) {
|
|
201
122
|
let accumulator = argument1;
|
|
202
|
-
|
|
203
|
-
console.log(text);
|
|
123
|
+
useLog(accumulator).collect(this);
|
|
204
124
|
}
|
|
205
|
-
else {
|
|
125
|
+
else if (isString(argument1) && isFunction(argument2) && isString(argument3)) {
|
|
126
|
+
let prefix = argument1;
|
|
127
|
+
let accumulator = argument2;
|
|
128
|
+
let suffix = argument3;
|
|
129
|
+
useLog(prefix, accumulator, suffix).collect(this);
|
|
130
|
+
}
|
|
131
|
+
{
|
|
206
132
|
throw new TypeError("Invalid arguments.");
|
|
207
133
|
}
|
|
208
134
|
}
|
|
209
135
|
nonMatch(predicate) {
|
|
210
|
-
|
|
211
|
-
return
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
}, (result, element) => {
|
|
215
|
-
return result || !predicate(element);
|
|
216
|
-
}, (result) => {
|
|
217
|
-
return result;
|
|
218
|
-
});
|
|
136
|
+
if (isFunction(predicate)) {
|
|
137
|
+
return useNoneMatch(predicate).collect(this);
|
|
138
|
+
}
|
|
139
|
+
throw new TypeError("Predicate must be a function.");
|
|
219
140
|
}
|
|
220
141
|
partition(count) {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
let index = limited % BigInt(array.length);
|
|
226
|
-
if (index === 0n) {
|
|
227
|
-
array.push([]);
|
|
228
|
-
}
|
|
229
|
-
array[Number(index)].push(element);
|
|
230
|
-
return array;
|
|
231
|
-
}, (result) => {
|
|
232
|
-
return result;
|
|
233
|
-
});
|
|
142
|
+
if (isBigInt(count)) {
|
|
143
|
+
return usePartition(count).collect(this);
|
|
144
|
+
}
|
|
145
|
+
throw new TypeError("Count must be a BigInt.");
|
|
234
146
|
}
|
|
235
147
|
partitionBy(classifier) {
|
|
236
148
|
return this.collect(() => {
|
|
@@ -249,30 +161,18 @@ export class Collectable {
|
|
|
249
161
|
reduce(argument1, argument2, argument3) {
|
|
250
162
|
if (isFunction(argument1) && invalidate(argument2) && invalidate(argument3)) {
|
|
251
163
|
let accumulator = argument1;
|
|
252
|
-
return
|
|
253
|
-
if (result.isEmpty()) {
|
|
254
|
-
return Optional.of(element);
|
|
255
|
-
}
|
|
256
|
-
else {
|
|
257
|
-
let current = result.get();
|
|
258
|
-
return Optional.of(accumulator(current, element, index));
|
|
259
|
-
}
|
|
260
|
-
}, (result) => result);
|
|
164
|
+
return useReduce(accumulator).collect(this);
|
|
261
165
|
}
|
|
262
166
|
else if (validate(argument1) && isFunction(argument2) && invalidate(argument3)) {
|
|
263
167
|
let identity = argument1;
|
|
264
168
|
let accumulator = argument2;
|
|
265
|
-
return
|
|
266
|
-
return accumulator(result, element, index);
|
|
267
|
-
}, (result) => result);
|
|
169
|
+
return useReduce(identity, accumulator).collect(this);
|
|
268
170
|
}
|
|
269
171
|
else if (validate(argument1) && isFunction(argument2) && isFunction(argument3)) {
|
|
270
172
|
let identity = argument1;
|
|
271
173
|
let accumulator = argument2;
|
|
272
174
|
let finisher = argument3;
|
|
273
|
-
return
|
|
274
|
-
return accumulator(result, element, index);
|
|
275
|
-
}, (result) => finisher(result, result));
|
|
175
|
+
return useReduce(identity, accumulator, finisher).collect(this);
|
|
276
176
|
}
|
|
277
177
|
else {
|
|
278
178
|
throw new TypeError("Invalid arguments.");
|
|
@@ -291,83 +191,26 @@ export class Collectable {
|
|
|
291
191
|
}
|
|
292
192
|
}
|
|
293
193
|
toArray() {
|
|
294
|
-
return
|
|
295
|
-
return [];
|
|
296
|
-
}, (array, element) => {
|
|
297
|
-
array.push(element);
|
|
298
|
-
return array;
|
|
299
|
-
}, (result) => {
|
|
300
|
-
return result;
|
|
301
|
-
});
|
|
194
|
+
return useToArray().collect(this);
|
|
302
195
|
}
|
|
303
196
|
toMap(keyExtractor, valueExtractor) {
|
|
304
|
-
return
|
|
305
|
-
return new Map();
|
|
306
|
-
}, (map, element) => {
|
|
307
|
-
let key = keyExtractor(element);
|
|
308
|
-
let value = valueExtractor(element);
|
|
309
|
-
map.set(key, value);
|
|
310
|
-
return map;
|
|
311
|
-
}, (map) => {
|
|
312
|
-
return map;
|
|
313
|
-
});
|
|
197
|
+
return useToMap(keyExtractor, valueExtractor).collect(this);
|
|
314
198
|
}
|
|
315
199
|
toSet() {
|
|
316
|
-
return
|
|
317
|
-
return new Set();
|
|
318
|
-
}, (set, element) => {
|
|
319
|
-
set.add(element);
|
|
320
|
-
return set;
|
|
321
|
-
}, (result) => {
|
|
322
|
-
return result;
|
|
323
|
-
});
|
|
200
|
+
return useToSet().collect(this);
|
|
324
201
|
}
|
|
325
|
-
write(
|
|
326
|
-
if (isObject(
|
|
327
|
-
let
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
});
|
|
336
|
-
}
|
|
337
|
-
catch (reason) {
|
|
338
|
-
return Optional.empty();
|
|
339
|
-
}
|
|
340
|
-
}, (a) => {
|
|
341
|
-
return a;
|
|
342
|
-
});
|
|
343
|
-
return new Promise((resolve, reject) => {
|
|
344
|
-
optional.ifPresent(resolve, reject);
|
|
345
|
-
});
|
|
346
|
-
}
|
|
347
|
-
else if (isObject(stream) && isFunction(accumulator)) {
|
|
348
|
-
let optional = this.collect(() => {
|
|
349
|
-
return Optional.ofNonNull(stream);
|
|
350
|
-
}, (result, element, index) => {
|
|
351
|
-
try {
|
|
352
|
-
return result.map((stream) => {
|
|
353
|
-
let writer = stream.getWriter();
|
|
354
|
-
writer.write(accumulator(element, index));
|
|
355
|
-
return stream;
|
|
356
|
-
});
|
|
357
|
-
}
|
|
358
|
-
catch (reason) {
|
|
359
|
-
return Optional.empty();
|
|
360
|
-
}
|
|
361
|
-
}, (a) => {
|
|
362
|
-
return a;
|
|
363
|
-
});
|
|
364
|
-
return new Promise((resolve, reject) => {
|
|
365
|
-
optional.ifPresent(resolve, reject);
|
|
366
|
-
});
|
|
367
|
-
}
|
|
368
|
-
else {
|
|
369
|
-
throw new TypeError("Invalid arguments.");
|
|
202
|
+
write(argument1, argument2) {
|
|
203
|
+
if (isObject(argument1)) {
|
|
204
|
+
let stream = argument1;
|
|
205
|
+
if (isFunction(argument2)) {
|
|
206
|
+
let accumulator = argument2;
|
|
207
|
+
return useWrite(stream, accumulator);
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
return useWrite(stream);
|
|
211
|
+
}
|
|
370
212
|
}
|
|
213
|
+
throw new TypeError("Invalid arguments.");
|
|
371
214
|
}
|
|
372
215
|
}
|
|
373
216
|
;
|
package/dist/collector.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import type { Collectable } from "./collectable";
|
|
2
|
+
import { Optional } from "./optional";
|
|
1
3
|
import type { Semantic } from "./semantic";
|
|
2
|
-
import type
|
|
4
|
+
import { type BiFunctional, type BiPredicate, type Functional, type Predicate, type Supplier, type TriFunctional, type Generator, type TriPredicate, type Consumer, type BiConsumer } from "./utility";
|
|
3
5
|
export declare class Collector<E, A, R> {
|
|
4
6
|
protected identity: Supplier<A>;
|
|
5
7
|
protected interrupt: Predicate<E> | BiPredicate<E, bigint> | TriPredicate<E, bigint, A>;
|
|
@@ -13,6 +15,7 @@ export declare class Collector<E, A, R> {
|
|
|
13
15
|
collect(generator: Generator<E>): R;
|
|
14
16
|
collect(iterable: Iterable<E>): R;
|
|
15
17
|
collect(semantic: Semantic<E>): R;
|
|
18
|
+
collect(collectable: Collectable<E>): R;
|
|
16
19
|
collect(start: number, end: number): R;
|
|
17
20
|
collect(start: bigint, end: bigint): R;
|
|
18
21
|
static full<E, A, R>(identity: Supplier<A>, accumulator: BiFunctional<A, E, A>, finisher: Functional<A, R>): Collector<E, A, R>;
|
|
@@ -24,3 +27,98 @@ export declare class Collector<E, A, R> {
|
|
|
24
27
|
static shortable<E, A, R>(identity: Supplier<A>, interruptor: TriPredicate<E, bigint, A>, accumulator: BiFunctional<A, E, A>, finisher: Functional<A, R>): Collector<E, A, R>;
|
|
25
28
|
static shortable<E, A, R>(identity: Supplier<A>, interruptor: TriPredicate<E, bigint, A>, accumulator: TriFunctional<A, E, bigint, A>, finisher: Functional<A, R>): Collector<E, A, R>;
|
|
26
29
|
}
|
|
30
|
+
export declare let useAnyMatch: <E>(predicate: Predicate<E>) => Collector<E, boolean, boolean>;
|
|
31
|
+
export declare let useAllMatch: <E>(predicate: Predicate<E>) => Collector<E, boolean, boolean>;
|
|
32
|
+
interface UseCollect {
|
|
33
|
+
<E, A, R>(identity: Supplier<A>, accumulator: BiFunctional<A, E, A>, finisher: Functional<A, R>): Collector<E, A, R>;
|
|
34
|
+
<E, A, R>(identity: Supplier<A>, accumulator: TriFunctional<A, E, bigint, A>, finisher: Functional<A, R>): Collector<E, A, R>;
|
|
35
|
+
<E, A, R>(identity: Supplier<A>, accumulator: BiFunctional<A, E, A> | TriFunctional<A, E, bigint, A>, finisher: Functional<A, R>): Collector<E, A, R>;
|
|
36
|
+
<E, A, R>(identity: Supplier<A>, interruptor: Predicate<E>, accumulator: BiFunctional<A, E, A>, finisher: Functional<A, R>): Collector<E, A, R>;
|
|
37
|
+
<E, A, R>(identity: Supplier<A>, interruptor: Predicate<E>, accumulator: TriFunctional<A, E, bigint, A>, finisher: Functional<A, R>): Collector<E, A, R>;
|
|
38
|
+
<E, A, R>(identity: Supplier<A>, interruptor: BiPredicate<E, bigint>, accumulator: BiFunctional<A, E, A>, finisher: Functional<A, R>): Collector<E, A, R>;
|
|
39
|
+
<E, A, R>(identity: Supplier<A>, interruptor: BiPredicate<E, bigint>, accumulator: TriFunctional<A, E, bigint, A>, finisher: Functional<A, R>): Collector<E, A, R>;
|
|
40
|
+
<E, A, R>(identity: Supplier<A>, interruptor: TriPredicate<E, bigint, A>, accumulator: BiFunctional<A, E, A>, finisher: Functional<A, R>): Collector<E, A, R>;
|
|
41
|
+
<E, A, R>(identity: Supplier<A>, interruptor: TriPredicate<E, bigint, A>, accumulator: TriFunctional<A, E, bigint, A>, finisher: Functional<A, R>): Collector<E, A, R>;
|
|
42
|
+
}
|
|
43
|
+
export declare let useCollect: UseCollect;
|
|
44
|
+
export declare let useCount: <E = unknown>() => Collector<E, bigint, bigint>;
|
|
45
|
+
export interface UseError {
|
|
46
|
+
<E = unknown>(): Collector<E, string, string>;
|
|
47
|
+
<E = unknown>(accumulator: BiFunctional<string, E, string>): Collector<E, string, string>;
|
|
48
|
+
<E = unknown>(accumulator: TriFunctional<string, E, bigint, string>): Collector<E, string, string>;
|
|
49
|
+
<E = unknown>(prefix: string, accumulator: BiFunctional<string, E, string>, suffix: string): Collector<E, string, string>;
|
|
50
|
+
<E = unknown>(prefix: string, accumulator: TriFunctional<string, E, bigint, string>, suffix: string): Collector<E, string, string>;
|
|
51
|
+
}
|
|
52
|
+
export declare let useError: UseLog;
|
|
53
|
+
export declare let useFindFirst: <E>() => Collector<E, Optional<E>, Optional<E>>;
|
|
54
|
+
export declare let useFindAny: <E>() => Collector<E, Optional<E>, Optional<E>>;
|
|
55
|
+
export declare let useFindLast: <E>() => Collector<E, Optional<E>, Optional<E>>;
|
|
56
|
+
export interface UseForEach {
|
|
57
|
+
<E>(action: Consumer<E>): Collector<E, bigint, bigint>;
|
|
58
|
+
<E>(action: BiConsumer<E, bigint>): Collector<E, bigint, bigint>;
|
|
59
|
+
}
|
|
60
|
+
export declare let useForEach: UseForEach;
|
|
61
|
+
export declare let useNoneMatch: <E>(predicate: Predicate<E>) => Collector<E, boolean, boolean>;
|
|
62
|
+
export declare let useGroup: <E, K>(classifier: Functional<E, K>) => Collector<E, Map<K, E[]>, Map<K, E[]>>;
|
|
63
|
+
export declare let useGroupBy: <E, K, V>(keyExtractor: Functional<E, K>, valueExtractor: Functional<E, V>) => Collector<E, Map<K, V[]>, Map<K, V[]>>;
|
|
64
|
+
export interface UseJoin {
|
|
65
|
+
<E = unknown>(): Collector<E, string, string>;
|
|
66
|
+
<E = unknown>(delimiter: string): Collector<E, string, string>;
|
|
67
|
+
<E = unknown>(prefix: string, delimiter: string, suffix: string): Collector<E, string, string>;
|
|
68
|
+
<E = unknown>(prefiex: string, accumulator: BiFunctional<string, E, string>, suffix: string): Collector<E, string, string>;
|
|
69
|
+
<E = unknown>(prefiex: string, accumulator: TriFunctional<string, E, bigint, string>, suffix: string): Collector<E, string, string>;
|
|
70
|
+
}
|
|
71
|
+
export declare let useJoin: UseJoin;
|
|
72
|
+
export interface UseLog {
|
|
73
|
+
<E = unknown>(): Collector<E, string, string>;
|
|
74
|
+
<E = unknown>(accumulator: BiFunctional<string, E, string>): Collector<E, string, string>;
|
|
75
|
+
<E = unknown>(accumulator: TriFunctional<string, E, bigint, string>): Collector<E, string, string>;
|
|
76
|
+
<E = unknown>(prefix: string, accumulator: BiFunctional<string, E, string>, suffix: string): Collector<E, string, string>;
|
|
77
|
+
<E = unknown>(prefix: string, accumulator: TriFunctional<string, E, bigint, string>, suffix: string): Collector<E, string, string>;
|
|
78
|
+
}
|
|
79
|
+
export declare let useLog: UseLog;
|
|
80
|
+
export declare let usePartition: <E>(count: bigint) => Collector<E, Array<Array<E>>, Array<Array<E>>>;
|
|
81
|
+
export declare let usePartitionBy: <E>(classifier: Functional<E, bigint>) => Collector<E, Array<E[]>, Array<E[]>>;
|
|
82
|
+
export interface UseReduce {
|
|
83
|
+
<E>(accumulator: BiFunctional<E, E, E>): Collector<E, Optional<E>, Optional<E>>;
|
|
84
|
+
<E>(accumulator: TriFunctional<E, E, bigint, E>): Collector<E, Optional<E>, Optional<E>>;
|
|
85
|
+
<E>(identity: E, accumulator: BiFunctional<E, E, E>): Collector<E, E, E>;
|
|
86
|
+
<E>(identity: E, accumulator: TriFunctional<E, E, bigint, E>): Collector<E, E, E>;
|
|
87
|
+
<E, R>(identity: R, accumulator: BiFunctional<R, E, R>, finisher: Functional<R, R>): Collector<E, R, R>;
|
|
88
|
+
<E, R>(identity: R, accumulator: TriFunctional<R, E, bigint, R>, finisher: Functional<R, R>): Collector<E, R, R>;
|
|
89
|
+
}
|
|
90
|
+
export declare let useReduce: UseReduce;
|
|
91
|
+
export declare let useToArray: <E>() => Collector<E, E[], E[]>;
|
|
92
|
+
export declare let useToMap: <E, K, V>(keyExtractor: Functional<E, K>, valueExtractor: Functional<E, V>) => Collector<E, Map<K, V>, Map<K, V>>;
|
|
93
|
+
export declare let useToSet: <E>() => Collector<E, Set<E>, Set<E>>;
|
|
94
|
+
export interface UseWrite {
|
|
95
|
+
<E, S = string>(stream: WritableStream<S>): Collector<E, Promise<WritableStream<S>>, Promise<WritableStream<S>>>;
|
|
96
|
+
<E, S = string>(stream: WritableStream<S>, accumulator: BiFunctional<WritableStream<S>, E, WritableStream<S>>): Collector<E, Promise<WritableStream<S>>, Promise<WritableStream<S>>>;
|
|
97
|
+
<E, S = string>(stream: WritableStream<S>, accumulator: TriFunctional<WritableStream<S>, E, bigint, WritableStream<S>>): Collector<E, Promise<WritableStream<S>>, Promise<WritableStream<S>>>;
|
|
98
|
+
}
|
|
99
|
+
export declare let useWrite: UseWrite;
|
|
100
|
+
export type NumericAverageInformation = {
|
|
101
|
+
summate: number;
|
|
102
|
+
count: number;
|
|
103
|
+
};
|
|
104
|
+
export interface UseNumericAverage {
|
|
105
|
+
(): Collector<number, NumericAverageInformation, number>;
|
|
106
|
+
<E>(mapper: Functional<E, number>): Collector<E, NumericAverageInformation, number>;
|
|
107
|
+
}
|
|
108
|
+
export declare let useNumericAverage: UseNumericAverage;
|
|
109
|
+
export type BigIntAverageInformation = {
|
|
110
|
+
summate: bigint;
|
|
111
|
+
count: bigint;
|
|
112
|
+
};
|
|
113
|
+
export interface UseBigIntAverage {
|
|
114
|
+
(): Collector<bigint, BigIntAverageInformation, bigint>;
|
|
115
|
+
<E>(mapper: Functional<E, bigint>): Collector<E, BigIntAverageInformation, bigint>;
|
|
116
|
+
}
|
|
117
|
+
export declare let useBigIntAverage: UseBigIntAverage;
|
|
118
|
+
export declare let useFrequency: <E>() => Collector<E, Map<E, bigint>, Map<E, bigint>>;
|
|
119
|
+
export interface UseNumericSummate {
|
|
120
|
+
(): Collector<number, number, number>;
|
|
121
|
+
<E>(mapper: Functional<E, number>): Collector<E, number, number>;
|
|
122
|
+
}
|
|
123
|
+
export declare let useSummate: UseNumericSummate;
|
|
124
|
+
export {};
|