semantic-typescript 0.4.1 → 0.5.3
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/collector.d.ts +3 -9
- package/dist/collector.js +3 -22
- package/dist/factory.d.ts +72 -14
- package/dist/factory.js +441 -71
- package/dist/guard.d.ts +6 -10
- package/dist/guard.js +21 -20
- package/dist/hash.d.ts +1 -2
- package/dist/hash.js +9 -15
- package/dist/hook.d.ts +5 -1
- package/dist/hook.js +72 -19
- package/dist/index.d.ts +0 -6
- package/dist/index.js +0 -6
- package/dist/main.d.ts +1 -0
- package/dist/main.js +4 -0
- package/dist/map.d.ts +4 -0
- package/dist/map.js +4 -6
- package/dist/node.d.ts +182 -0
- package/dist/node.js +918 -0
- package/dist/optional.d.ts +6 -3
- package/dist/optional.js +30 -8
- package/dist/semantic.d.ts +204 -4
- package/dist/semantic.js +1135 -13
- package/dist/set.js +1 -0
- package/dist/symbol.d.ts +1 -8
- package/dist/symbol.js +1 -8
- package/dist/tree.d.ts +82 -0
- package/dist/tree.js +257 -0
- package/dist/utility.d.ts +1 -1
- package/package.json +1 -1
- package/readme.md +492 -282
- package/dist/collectable.d.ts +0 -96
- package/dist/collectable.js +0 -554
- package/dist/statistics.d.ts +0 -97
- package/dist/statistics.js +0 -483
- package/dist/window.d.ts +0 -12
- package/dist/window.js +0 -72
package/dist/collectable.d.ts
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { Collector } from "./collector";
|
|
2
|
-
import type { HashMap } from "./map";
|
|
3
|
-
import { Optional } from "./optional";
|
|
4
|
-
import { Semantic } from "./semantic";
|
|
5
|
-
import type { HashSet } from "./set";
|
|
6
|
-
import type { BiConsumer, BiFunctional, Comparator, Consumer, Functional, Predicate, Supplier, TriFunctional, Generator, BiPredicate, TriPredicate, Indexed } from "./utility";
|
|
7
|
-
export declare abstract class Collectable<E> implements Iterable<E>, AsyncIterable<E> {
|
|
8
|
-
protected readonly Collectable: symbol;
|
|
9
|
-
constructor();
|
|
10
|
-
abstract [Symbol.iterator](): globalThis.Generator<E, void, undefined>;
|
|
11
|
-
abstract [Symbol.asyncIterator](): globalThis.AsyncGenerator<E, void, undefined>;
|
|
12
|
-
anyMatch(predicate: Predicate<E>): boolean;
|
|
13
|
-
allMatch(predicate: Predicate<E>): boolean;
|
|
14
|
-
collect<A, R>(collector: Collector<E, A, R>): R;
|
|
15
|
-
collect<A, R>(identity: Supplier<A>, accumulator: BiFunctional<A, E, A>, finisher: Functional<A, R>): R;
|
|
16
|
-
collect<A, R>(identity: Supplier<A>, accumulator: TriFunctional<A, E, bigint, A>, finisher: Functional<A, R>): R;
|
|
17
|
-
collect<A, R>(identity: Supplier<A>, interruptor: Predicate<E>, accumulator: BiFunctional<A, E, A>, finisher: Functional<A, R>): R;
|
|
18
|
-
collect<A, R>(identity: Supplier<A>, interruptor: BiPredicate<E, bigint>, accumulator: BiFunctional<A, E, A>, finisher: Functional<A, R>): R;
|
|
19
|
-
collect<A, R>(identity: Supplier<A>, interruptor: TriPredicate<E, bigint, A>, accumulator: BiFunctional<A, E, A>, finisher: Functional<A, R>): R;
|
|
20
|
-
collect<A, R>(identity: Supplier<A>, interruptor: Predicate<E>, accumulator: TriFunctional<A, E, bigint, A>, finisher: Functional<A, R>): R;
|
|
21
|
-
collect<A, R>(identity: Supplier<A>, interruptor: BiPredicate<E, bigint>, accumulator: TriFunctional<A, E, bigint, A>, finisher: Functional<A, R>): R;
|
|
22
|
-
collect<A, R>(identity: Supplier<A>, interruptor: TriPredicate<E, bigint, A>, accumulator: TriFunctional<A, E, bigint, A>, finisher: Functional<A, R>): R;
|
|
23
|
-
count(): bigint;
|
|
24
|
-
error(): void;
|
|
25
|
-
error(accumulator: BiFunctional<string, E, string>): void;
|
|
26
|
-
error(accumulator: TriFunctional<string, E, bigint, string>): void;
|
|
27
|
-
error(prefix: string, accumulator: BiFunctional<string, E, string>, suffix: string): void;
|
|
28
|
-
error(prefix: string, accumulator: TriFunctional<string, E, bigint, string>, suffix: string): void;
|
|
29
|
-
isEmpty(): boolean;
|
|
30
|
-
findAny(): Optional<E>;
|
|
31
|
-
findAt(index: number): Optional<E>;
|
|
32
|
-
findAt(index: bigint): Optional<E>;
|
|
33
|
-
findFirst(): Optional<E>;
|
|
34
|
-
findLast(): Optional<E>;
|
|
35
|
-
findMaximum(): Optional<E>;
|
|
36
|
-
findMaximum(comparator: Comparator<E>): Optional<E>;
|
|
37
|
-
findMinimum(): Optional<E>;
|
|
38
|
-
findMinimum(comparator: Comparator<E>): Optional<E>;
|
|
39
|
-
forEach(action: Consumer<E>): void;
|
|
40
|
-
forEach(action: BiConsumer<E, bigint>): void;
|
|
41
|
-
group<K>(classifier: Functional<E, K>): Map<K, Array<E>>;
|
|
42
|
-
group<K>(classifier: BiFunctional<E, bigint, K>): Map<K, Array<E>>;
|
|
43
|
-
groupBy<K, V>(keyExtractor: Functional<E, K>, valueExtractor: Functional<E, V>): Map<K, Array<V>>;
|
|
44
|
-
groupBy<K, V>(keyExtractor: BiFunctional<E, bigint, K>, valueExtractor: BiFunctional<E, bigint, K>): Map<K, Array<V>>;
|
|
45
|
-
join(): string;
|
|
46
|
-
join(delimiter: string): string;
|
|
47
|
-
join(prefix: string, delimiter: string, suffix: string): string;
|
|
48
|
-
join(prefiex: string, accumulator: BiFunctional<string, E, string>, suffix: string): string;
|
|
49
|
-
join(prefiex: string, accumulator: TriFunctional<string, E, bigint, string>, suffix: string): string;
|
|
50
|
-
log(): void;
|
|
51
|
-
log(accumulator: BiFunctional<string, E, string>): void;
|
|
52
|
-
log(accumulator: TriFunctional<string, E, bigint, string>): void;
|
|
53
|
-
log(prefix: string, accumulator: BiFunctional<string, E, string>, suffix: string): void;
|
|
54
|
-
log(prefix: string, accumulator: TriFunctional<string, E, bigint, string>, suffix: string): void;
|
|
55
|
-
nonMatch(predicate: Predicate<E>): boolean;
|
|
56
|
-
nonMatch(predicate: BiPredicate<E, bigint>): boolean;
|
|
57
|
-
partition(count: bigint): Array<Array<E>>;
|
|
58
|
-
partitionBy(classifier: Functional<E, bigint>): Array<Array<E>>;
|
|
59
|
-
partitionBy(classifier: BiFunctional<E, bigint, bigint>): Array<Array<E>>;
|
|
60
|
-
reduce(accumulator: BiFunctional<E, E, E>): Optional<E>;
|
|
61
|
-
reduce(accumulator: TriFunctional<E, E, bigint, E>): Optional<E>;
|
|
62
|
-
reduce(identity: E, accumulator: BiFunctional<E, E, E>): E;
|
|
63
|
-
reduce(identity: E, accumulator: TriFunctional<E, E, bigint, E>): E;
|
|
64
|
-
reduce<R>(identity: R, accumulator: BiFunctional<R, E, R>, finisher: Functional<R, R>): R;
|
|
65
|
-
reduce<R>(identity: R, accumulator: TriFunctional<R, E, bigint, R>, finisher: Functional<R, R>): R;
|
|
66
|
-
semantic(): Semantic<E>;
|
|
67
|
-
abstract source(): Generator<E>;
|
|
68
|
-
toArray(): Array<E>;
|
|
69
|
-
toMap<K, V>(keyExtractor: Functional<E, K>, valueExtractor: Functional<E, V>): Map<K, V>;
|
|
70
|
-
toMap<K, V>(keyExtractor: BiFunctional<E, bigint, K>, valueExtractor: BiFunctional<E, bigint, V>): Map<K, V>;
|
|
71
|
-
toHashMap<K, V>(keyExtractor: Functional<E, K>, valueExtractor: Functional<E, V>): HashMap<K, V>;
|
|
72
|
-
toHashMap<K, V>(keyExtractor: BiFunctional<E, bigint, K>, valueExtractor: BiFunctional<E, bigint, V>): HashMap<K, V>;
|
|
73
|
-
toSet(): Set<E>;
|
|
74
|
-
toHashSet(): HashSet<E>;
|
|
75
|
-
write<S = string>(stream: WritableStream<S>): Promise<WritableStream<S>>;
|
|
76
|
-
write<S = string>(stream: WritableStream<S>, accumulator: BiFunctional<WritableStream<S>, E, WritableStream<S>>): Promise<WritableStream<S>>;
|
|
77
|
-
write<S = string>(stream: WritableStream<S>, accumulator: TriFunctional<WritableStream<S>, E, bigint, WritableStream<S>>): Promise<WritableStream<S>>;
|
|
78
|
-
}
|
|
79
|
-
export declare class UnorderedCollectable<E> extends Collectable<E> {
|
|
80
|
-
protected readonly UnorderedCollectable: symbol;
|
|
81
|
-
protected generator: Generator<E>;
|
|
82
|
-
constructor(generator: Generator<E>);
|
|
83
|
-
source(): Generator<E>;
|
|
84
|
-
[Symbol.iterator](): globalThis.Generator<E, void, undefined>;
|
|
85
|
-
[Symbol.asyncIterator](): globalThis.AsyncGenerator<E, void, undefined>;
|
|
86
|
-
}
|
|
87
|
-
export declare class OrderedCollectable<E> extends Collectable<E> {
|
|
88
|
-
protected readonly OrderedCollectable: symbol;
|
|
89
|
-
protected buffer: Array<Indexed<E>>;
|
|
90
|
-
constructor(generator: Generator<E>);
|
|
91
|
-
constructor(generator: Generator<E>, comparator: Comparator<E>);
|
|
92
|
-
[Symbol.iterator](): globalThis.Generator<E, void, undefined>;
|
|
93
|
-
[Symbol.asyncIterator](): globalThis.AsyncGenerator<E, void, undefined>;
|
|
94
|
-
source(): Generator<E>;
|
|
95
|
-
isEmpty(): boolean;
|
|
96
|
-
}
|
package/dist/collectable.js
DELETED
|
@@ -1,554 +0,0 @@
|
|
|
1
|
-
import { Collector, useAllMatch, useAnyMatch, useCollect, useCount, useError, useFindAny, useFindAt, useFindFirst, useFindLast, useFindMaximum, useFindMinimum, useForEach, useGroup, useGroupBy, useJoin, useLog, useNoneMatch, usePartition, usePartitionBy, useReduce, useToArray, useToAsyncGeneratorFunction, useToGeneratorFunction, useToHashMap, useToHashSet, useToMap, useToSet, useWrite } from "./collector";
|
|
2
|
-
import { isBigInt, isCollector, isFunction, isNumber, isObject, isString } from "./guard";
|
|
3
|
-
import { useCompare } from "./hook";
|
|
4
|
-
import { Optional } from "./optional";
|
|
5
|
-
import { Semantic } from "./semantic";
|
|
6
|
-
import { CollectableSymbol, OrderedCollectableSymbol, UnorderedCollectableSymbol } from "./symbol";
|
|
7
|
-
import { invalidate, validate } from "./utility";
|
|
8
|
-
export class Collectable {
|
|
9
|
-
Collectable = CollectableSymbol;
|
|
10
|
-
constructor() {
|
|
11
|
-
Object.defineProperty(this, "Collectable", {
|
|
12
|
-
value: CollectableSymbol,
|
|
13
|
-
enumerable: false,
|
|
14
|
-
writable: false,
|
|
15
|
-
configurable: false
|
|
16
|
-
});
|
|
17
|
-
Object.freeze(this);
|
|
18
|
-
}
|
|
19
|
-
anyMatch(predicate) {
|
|
20
|
-
if (isFunction(predicate)) {
|
|
21
|
-
try {
|
|
22
|
-
return useAnyMatch(predicate).collect(this);
|
|
23
|
-
}
|
|
24
|
-
catch (error) {
|
|
25
|
-
throw new Error("Uncaught error on anyMatch.");
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
throw new TypeError("Predicate must be a function.");
|
|
29
|
-
}
|
|
30
|
-
allMatch(predicate) {
|
|
31
|
-
return useAllMatch(predicate).collect(this);
|
|
32
|
-
}
|
|
33
|
-
collect(argument1, argument2, argument3, argument4) {
|
|
34
|
-
try {
|
|
35
|
-
if (isCollector(argument1)) {
|
|
36
|
-
let collector = argument1;
|
|
37
|
-
return collector.collect(this);
|
|
38
|
-
}
|
|
39
|
-
if (isFunction(argument1) && isFunction(argument2) && isFunction(argument3)) {
|
|
40
|
-
let identity = argument1;
|
|
41
|
-
let accumulator = argument2;
|
|
42
|
-
let finisher = argument3;
|
|
43
|
-
return useCollect(identity, accumulator, finisher).collect(this);
|
|
44
|
-
}
|
|
45
|
-
if (isFunction(argument1) && isFunction(argument2) && isFunction(argument3) && isFunction(argument4)) {
|
|
46
|
-
let identity = argument1;
|
|
47
|
-
let interrupt = argument2;
|
|
48
|
-
let accumulator = argument3;
|
|
49
|
-
let finisher = argument4;
|
|
50
|
-
return useCollect(identity, interrupt, accumulator, finisher).collect(this);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
catch (error) {
|
|
54
|
-
throw new Error("Uncaught error on collect.");
|
|
55
|
-
}
|
|
56
|
-
throw new TypeError("Invalid arguments.");
|
|
57
|
-
}
|
|
58
|
-
count() {
|
|
59
|
-
return useCount().collect(this.source());
|
|
60
|
-
}
|
|
61
|
-
error(argument1, argument2, argument3) {
|
|
62
|
-
if (invalidate(argument1) && invalidate(argument2) && invalidate(argument3)) {
|
|
63
|
-
try {
|
|
64
|
-
useError().collect(this.source());
|
|
65
|
-
}
|
|
66
|
-
catch (error) {
|
|
67
|
-
throw new Error("Uncaught error on error.");
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
else if (isFunction(argument1) && invalidate(argument2) && invalidate(argument3)) {
|
|
71
|
-
try {
|
|
72
|
-
let accumulator = argument1;
|
|
73
|
-
useError(accumulator).collect(this.source());
|
|
74
|
-
}
|
|
75
|
-
catch (error) {
|
|
76
|
-
throw new Error("Uncaught error on error.");
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
else if (isString(argument1) && isFunction(argument2) && isString(argument3)) {
|
|
80
|
-
try {
|
|
81
|
-
let prefix = argument1;
|
|
82
|
-
let accumulator = argument2;
|
|
83
|
-
let suffix = argument3;
|
|
84
|
-
useError(prefix, accumulator, suffix).collect(this.source());
|
|
85
|
-
}
|
|
86
|
-
catch (error) {
|
|
87
|
-
throw new Error("Uncaught error on error.");
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
throw new TypeError("Invalid arguments.");
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
isEmpty() {
|
|
95
|
-
return this.count() === 0n;
|
|
96
|
-
}
|
|
97
|
-
findAny() {
|
|
98
|
-
try {
|
|
99
|
-
return useFindAny().collect(this.source());
|
|
100
|
-
}
|
|
101
|
-
catch (error) {
|
|
102
|
-
throw new Error("Uncaught error on findAny.");
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
findAt(index) {
|
|
106
|
-
if (isBigInt(index)) {
|
|
107
|
-
try {
|
|
108
|
-
return useFindAt(index).collect(this.source());
|
|
109
|
-
}
|
|
110
|
-
catch (error) {
|
|
111
|
-
throw new Error("Uncaught error on findAt.");
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
else if (isNumber(index)) {
|
|
115
|
-
try {
|
|
116
|
-
return useFindAt(index).collect(this.source());
|
|
117
|
-
}
|
|
118
|
-
catch (error) {
|
|
119
|
-
throw new Error("Uncaught error on findAt.");
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
throw new TypeError("Index must be a bigint.");
|
|
123
|
-
}
|
|
124
|
-
findFirst() {
|
|
125
|
-
try {
|
|
126
|
-
return useFindFirst().collect(this.source());
|
|
127
|
-
}
|
|
128
|
-
catch (error) {
|
|
129
|
-
throw new Error("Uncaught error on findFirst.");
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
findLast() {
|
|
133
|
-
try {
|
|
134
|
-
return useFindLast().collect(this.source());
|
|
135
|
-
}
|
|
136
|
-
catch (error) {
|
|
137
|
-
throw new Error("Uncaught error on findLast.");
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
findMaximum(argument1) {
|
|
141
|
-
try {
|
|
142
|
-
let comparator = isFunction(argument1) ? argument1 : useCompare;
|
|
143
|
-
return useFindMaximum(comparator).collect(this.source());
|
|
144
|
-
}
|
|
145
|
-
catch (error) {
|
|
146
|
-
throw new Error("Uncaught error on findMaximum.");
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
findMinimum(argument1) {
|
|
150
|
-
try {
|
|
151
|
-
let comparator = isFunction(argument1) ? argument1 : useCompare;
|
|
152
|
-
return useFindMinimum(comparator).collect(this.source());
|
|
153
|
-
}
|
|
154
|
-
catch (error) {
|
|
155
|
-
throw new Error("Uncaught error on findMinimum.");
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
forEach(action) {
|
|
159
|
-
if (isFunction(action)) {
|
|
160
|
-
try {
|
|
161
|
-
useForEach(action).collect(this);
|
|
162
|
-
}
|
|
163
|
-
catch (error) {
|
|
164
|
-
throw new Error("Uncaught error on forEach.");
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
else {
|
|
168
|
-
throw new TypeError("Action must be a function.");
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
group(classifier) {
|
|
172
|
-
if (isFunction(classifier)) {
|
|
173
|
-
try {
|
|
174
|
-
return useGroup(classifier).collect(this.source());
|
|
175
|
-
}
|
|
176
|
-
catch (error) {
|
|
177
|
-
throw new Error("Uncaught error on group.");
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
throw new TypeError("Classifier must be a function.");
|
|
181
|
-
}
|
|
182
|
-
groupBy(keyExtractor, valueExtractor) {
|
|
183
|
-
if (isFunction(keyExtractor) && isFunction(valueExtractor)) {
|
|
184
|
-
try {
|
|
185
|
-
return useGroupBy(keyExtractor, valueExtractor).collect(this.source());
|
|
186
|
-
}
|
|
187
|
-
catch (error) {
|
|
188
|
-
throw new Error("Uncaught error on groupBy.");
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
throw new TypeError("Key and value extractors must be functions.");
|
|
192
|
-
}
|
|
193
|
-
join(argument1, argument2, argument3) {
|
|
194
|
-
if (invalidate(argument1) && invalidate(argument2) && invalidate(argument3)) {
|
|
195
|
-
try {
|
|
196
|
-
return useJoin().collect(this.source());
|
|
197
|
-
}
|
|
198
|
-
catch (error) {
|
|
199
|
-
throw new Error("Uncaught error on join.");
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
else if (isString(argument1) && invalidate(argument2) && invalidate(argument3)) {
|
|
203
|
-
try {
|
|
204
|
-
let delimiter = argument1;
|
|
205
|
-
return useJoin(delimiter).collect(this.source());
|
|
206
|
-
}
|
|
207
|
-
catch (error) {
|
|
208
|
-
throw new Error("Uncaught error on join.");
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
else if (isString(argument1) && isFunction(argument2) && isString(argument3)) {
|
|
212
|
-
try {
|
|
213
|
-
let prefix = argument1;
|
|
214
|
-
let accumulator = argument2;
|
|
215
|
-
let suffix = argument3;
|
|
216
|
-
return useJoin(prefix, accumulator, suffix).collect(this.source());
|
|
217
|
-
}
|
|
218
|
-
catch (error) {
|
|
219
|
-
throw new Error("Uncaught error on join.");
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
else if (isString(argument1) && isString(argument2) && isString(argument3)) {
|
|
223
|
-
try {
|
|
224
|
-
let prefix = argument1;
|
|
225
|
-
let delimiter = argument2;
|
|
226
|
-
let suffix = argument3;
|
|
227
|
-
return useJoin(prefix, delimiter, suffix).collect(this.source());
|
|
228
|
-
}
|
|
229
|
-
catch (error) {
|
|
230
|
-
throw new Error("Uncaught error on join.");
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
throw new TypeError("Invalid arguments.");
|
|
234
|
-
}
|
|
235
|
-
log(argument1, argument2, argument3) {
|
|
236
|
-
if (isFunction(argument1) && invalidate(argument2) && invalidate(argument3)) {
|
|
237
|
-
try {
|
|
238
|
-
let accumulator = argument1;
|
|
239
|
-
useLog(accumulator).collect(this.source());
|
|
240
|
-
}
|
|
241
|
-
catch (error) {
|
|
242
|
-
throw new Error("Uncaught error on log.");
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
else if (isString(argument1) && isFunction(argument2) && isString(argument3)) {
|
|
246
|
-
try {
|
|
247
|
-
let prefix = argument1;
|
|
248
|
-
let accumulator = argument2;
|
|
249
|
-
let suffix = argument3;
|
|
250
|
-
useLog(prefix, accumulator, suffix).collect(this.source());
|
|
251
|
-
}
|
|
252
|
-
catch (error) {
|
|
253
|
-
throw new Error("Uncaught error on log.");
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
else {
|
|
257
|
-
try {
|
|
258
|
-
useLog().collect(this.source());
|
|
259
|
-
}
|
|
260
|
-
catch (error) {
|
|
261
|
-
throw new Error("Uncaught error on log.");
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
nonMatch(predicate) {
|
|
266
|
-
if (isFunction(predicate)) {
|
|
267
|
-
try {
|
|
268
|
-
return useNoneMatch(predicate).collect(this.source());
|
|
269
|
-
}
|
|
270
|
-
catch (error) {
|
|
271
|
-
throw new Error("Uncaught error on nonMatch.");
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
throw new TypeError("Predicate must be a function.");
|
|
275
|
-
}
|
|
276
|
-
partition(count) {
|
|
277
|
-
if (isBigInt(count)) {
|
|
278
|
-
try {
|
|
279
|
-
return usePartition(count).collect(this.source());
|
|
280
|
-
}
|
|
281
|
-
catch (error) {
|
|
282
|
-
throw new Error("Uncaught error on partition.");
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
throw new TypeError("Count must be a BigInt.");
|
|
286
|
-
}
|
|
287
|
-
partitionBy(classifier) {
|
|
288
|
-
if (isFunction(classifier)) {
|
|
289
|
-
try {
|
|
290
|
-
let collector = usePartitionBy(classifier);
|
|
291
|
-
return collector.collect(this.source());
|
|
292
|
-
}
|
|
293
|
-
catch (error) {
|
|
294
|
-
throw new Error("Uncaught error on partitionBy.");
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
throw new TypeError("Classifier must be a function.");
|
|
298
|
-
}
|
|
299
|
-
reduce(argument1, argument2, argument3) {
|
|
300
|
-
if (isFunction(argument1) && invalidate(argument2) && invalidate(argument3)) {
|
|
301
|
-
try {
|
|
302
|
-
let accumulator = argument1;
|
|
303
|
-
return useReduce(accumulator).collect(this.source());
|
|
304
|
-
}
|
|
305
|
-
catch (error) {
|
|
306
|
-
throw new Error("Uncaught error on reduce.");
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
else if (validate(argument1) && isFunction(argument2) && invalidate(argument3)) {
|
|
310
|
-
try {
|
|
311
|
-
let identity = argument1;
|
|
312
|
-
let accumulator = argument2;
|
|
313
|
-
return useReduce(identity, accumulator).collect(this.source());
|
|
314
|
-
}
|
|
315
|
-
catch (error) {
|
|
316
|
-
throw new Error("Uncaught error on reduce.");
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
else if (validate(argument1) && isFunction(argument2) && isFunction(argument3)) {
|
|
320
|
-
try {
|
|
321
|
-
let identity = argument1;
|
|
322
|
-
let accumulator = argument2;
|
|
323
|
-
let finisher = argument3;
|
|
324
|
-
return useReduce(identity, accumulator, finisher).collect(this.source());
|
|
325
|
-
}
|
|
326
|
-
catch (error) {
|
|
327
|
-
throw new Error("Uncaught error on reduce.");
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
else {
|
|
331
|
-
throw new TypeError("Invalid arguments.");
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
semantic() {
|
|
335
|
-
let source = this.source();
|
|
336
|
-
if (isFunction(source)) {
|
|
337
|
-
try {
|
|
338
|
-
return new Semantic(source);
|
|
339
|
-
}
|
|
340
|
-
catch (error) {
|
|
341
|
-
throw new Error("Uncaught error on semantic.");
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
else {
|
|
345
|
-
throw new TypeError("Invalid source.");
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
toArray() {
|
|
349
|
-
try {
|
|
350
|
-
return useToArray().collect(this.source());
|
|
351
|
-
}
|
|
352
|
-
catch (error) {
|
|
353
|
-
throw new Error("Uncaught error on toArray.");
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
toMap(keyExtractor, valueExtractor) {
|
|
357
|
-
try {
|
|
358
|
-
return useToMap(keyExtractor, valueExtractor).collect(this.source());
|
|
359
|
-
}
|
|
360
|
-
catch (error) {
|
|
361
|
-
throw new Error("Uncaught error on toMap.");
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
toHashMap(keyExtractor, valueExtractor) {
|
|
365
|
-
try {
|
|
366
|
-
return useToHashMap(keyExtractor, valueExtractor).collect(this.source());
|
|
367
|
-
}
|
|
368
|
-
catch (error) {
|
|
369
|
-
throw new Error("Uncaught error on toHashMap.");
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
toSet() {
|
|
373
|
-
try {
|
|
374
|
-
return useToSet().collect(this.source());
|
|
375
|
-
}
|
|
376
|
-
catch (error) {
|
|
377
|
-
throw new Error("Uncaught error on toSet.");
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
toHashSet() {
|
|
381
|
-
try {
|
|
382
|
-
return useToHashSet().collect(this.source());
|
|
383
|
-
}
|
|
384
|
-
catch (error) {
|
|
385
|
-
throw new Error("Uncaught error on toHashSet.");
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
write(argument1, argument2) {
|
|
389
|
-
if (isObject(argument1)) {
|
|
390
|
-
try {
|
|
391
|
-
let stream = argument1;
|
|
392
|
-
if (isFunction(argument2)) {
|
|
393
|
-
let accumulator = argument2;
|
|
394
|
-
return useWrite(stream, accumulator).collect(this.source());
|
|
395
|
-
}
|
|
396
|
-
else {
|
|
397
|
-
return useWrite(stream).collect(this.source());
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
catch (error) {
|
|
401
|
-
throw new Error("Uncaught error on write.");
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
throw new TypeError("Invalid arguments.");
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
;
|
|
408
|
-
Object.freeze(Collectable);
|
|
409
|
-
Object.freeze(Collectable.prototype);
|
|
410
|
-
Object.freeze(Object.getPrototypeOf(Collectable));
|
|
411
|
-
export class UnorderedCollectable extends Collectable {
|
|
412
|
-
UnorderedCollectable = UnorderedCollectableSymbol;
|
|
413
|
-
generator;
|
|
414
|
-
constructor(argument1) {
|
|
415
|
-
super();
|
|
416
|
-
if (isFunction(argument1)) {
|
|
417
|
-
this.generator = argument1;
|
|
418
|
-
Object.defineProperties(this, {
|
|
419
|
-
"UnorderedCollectable": {
|
|
420
|
-
value: UnorderedCollectableSymbol,
|
|
421
|
-
writable: false,
|
|
422
|
-
enumerable: false,
|
|
423
|
-
configurable: false
|
|
424
|
-
},
|
|
425
|
-
"generator": {
|
|
426
|
-
value: argument1,
|
|
427
|
-
writable: false,
|
|
428
|
-
enumerable: false,
|
|
429
|
-
configurable: false
|
|
430
|
-
}
|
|
431
|
-
});
|
|
432
|
-
Object.freeze(this);
|
|
433
|
-
}
|
|
434
|
-
else {
|
|
435
|
-
throw new TypeError("Source must be an iterable or a generator function.");
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
source() {
|
|
439
|
-
return this.generator;
|
|
440
|
-
}
|
|
441
|
-
*[Symbol.iterator]() {
|
|
442
|
-
try {
|
|
443
|
-
let collector = useToGeneratorFunction();
|
|
444
|
-
yield* collector.collect(this.generator);
|
|
445
|
-
}
|
|
446
|
-
catch (error) {
|
|
447
|
-
throw new Error("Uncaught error on Generator.");
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
async *[Symbol.asyncIterator]() {
|
|
451
|
-
try {
|
|
452
|
-
let collector = useToAsyncGeneratorFunction();
|
|
453
|
-
yield* collector.collect(this.generator);
|
|
454
|
-
}
|
|
455
|
-
catch (error) {
|
|
456
|
-
throw new Error("Uncaught error on AsyncGenerator.");
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
;
|
|
461
|
-
Object.freeze(UnorderedCollectable);
|
|
462
|
-
Object.freeze(UnorderedCollectable.prototype);
|
|
463
|
-
Object.freeze(Object.getPrototypeOf(UnorderedCollectable));
|
|
464
|
-
export class OrderedCollectable extends Collectable {
|
|
465
|
-
OrderedCollectable = OrderedCollectableSymbol;
|
|
466
|
-
buffer;
|
|
467
|
-
constructor(argument1, argument2) {
|
|
468
|
-
super();
|
|
469
|
-
if (isFunction(argument1)) {
|
|
470
|
-
try {
|
|
471
|
-
if (isFunction(argument2)) {
|
|
472
|
-
let collector = useToArray();
|
|
473
|
-
this.buffer = collector.collect(argument1).sort(argument2).map((element, index) => {
|
|
474
|
-
return {
|
|
475
|
-
element: element,
|
|
476
|
-
index: BigInt(index)
|
|
477
|
-
};
|
|
478
|
-
});
|
|
479
|
-
}
|
|
480
|
-
else {
|
|
481
|
-
let collector = useToArray();
|
|
482
|
-
this.buffer = collector.collect(argument1).map((element, index) => {
|
|
483
|
-
return {
|
|
484
|
-
element: element,
|
|
485
|
-
index: BigInt(index)
|
|
486
|
-
};
|
|
487
|
-
}).sort((a, b) => {
|
|
488
|
-
return Number(a.index - b.index);
|
|
489
|
-
});
|
|
490
|
-
}
|
|
491
|
-
Object.defineProperties(this, {
|
|
492
|
-
"OrderedCollectable": {
|
|
493
|
-
value: OrderedCollectableSymbol,
|
|
494
|
-
writable: false,
|
|
495
|
-
enumerable: false,
|
|
496
|
-
configurable: false
|
|
497
|
-
},
|
|
498
|
-
"buffer": {
|
|
499
|
-
value: this.buffer,
|
|
500
|
-
writable: false,
|
|
501
|
-
enumerable: false,
|
|
502
|
-
configurable: false
|
|
503
|
-
}
|
|
504
|
-
});
|
|
505
|
-
}
|
|
506
|
-
catch (error) {
|
|
507
|
-
throw new Error("Uncaught error on creating buffer.");
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
else {
|
|
511
|
-
throw new TypeError("Source must be an iterable or a generator function.");
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
*[Symbol.iterator]() {
|
|
515
|
-
try {
|
|
516
|
-
let collector = useToGeneratorFunction();
|
|
517
|
-
yield* collector.collect(this.source());
|
|
518
|
-
}
|
|
519
|
-
catch (error) {
|
|
520
|
-
throw new Error("Uncaught error on Generator.");
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
async *[Symbol.asyncIterator]() {
|
|
524
|
-
try {
|
|
525
|
-
let collector = useToAsyncGeneratorFunction();
|
|
526
|
-
yield* collector.collect(this.source());
|
|
527
|
-
}
|
|
528
|
-
catch (error) {
|
|
529
|
-
throw new Error("Uncaught error on AsyncGenerator.");
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
source() {
|
|
533
|
-
try {
|
|
534
|
-
return (accept, interrupt) => {
|
|
535
|
-
for (let indexed of this.buffer) {
|
|
536
|
-
if (interrupt(indexed.element, indexed.index)) {
|
|
537
|
-
break;
|
|
538
|
-
}
|
|
539
|
-
accept(indexed.element, indexed.index);
|
|
540
|
-
}
|
|
541
|
-
};
|
|
542
|
-
}
|
|
543
|
-
catch (error) {
|
|
544
|
-
throw new Error("Uncaught error on creating source.");
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
isEmpty() {
|
|
548
|
-
return this.buffer.length === 0;
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
;
|
|
552
|
-
Object.freeze(OrderedCollectable);
|
|
553
|
-
Object.freeze(OrderedCollectable.prototype);
|
|
554
|
-
Object.freeze(Object.getPrototypeOf(OrderedCollectable));
|