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/optional.d.ts
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
import type { Semantic } from "./semantic";
|
|
2
|
-
import { type Consumer, type Functional, type MaybeInvalid, type Predicate, type Runnable } from "./utility";
|
|
2
|
+
import { type Consumer, type Functional, type MaybeInvalid, type Predicate, type Runnable, type Valid } from "./utility";
|
|
3
3
|
export declare class Optional<T> {
|
|
4
4
|
protected value: MaybeInvalid<T>;
|
|
5
5
|
protected readonly Optional: Symbol;
|
|
6
6
|
protected constructor(value: MaybeInvalid<T>);
|
|
7
7
|
filter(predicate: Predicate<T>): Optional<T>;
|
|
8
|
-
get(): T
|
|
9
|
-
get(defaultValue: T): T
|
|
8
|
+
get(): Valid<T>;
|
|
9
|
+
get(defaultValue: T): Valid<T>;
|
|
10
10
|
ifPresent(action: Consumer<T>): void;
|
|
11
11
|
ifPresent(action: Consumer<T>, elseAction: Runnable): void;
|
|
12
12
|
isEmpty(): boolean;
|
|
13
13
|
isPresent(): boolean;
|
|
14
14
|
map<R>(mapper: Functional<T, R>): Optional<R>;
|
|
15
|
+
flat(mapper: Functional<T, Optional<T>>): Optional<T>;
|
|
16
|
+
flatMap<R>(mapper: Functional<T, Optional<R>>): Optional<R>;
|
|
17
|
+
orElse(other: MaybeInvalid<T>): MaybeInvalid<T>;
|
|
15
18
|
semantic(): Semantic<T>;
|
|
16
19
|
static empty<T>(): Optional<T>;
|
|
17
20
|
static of<T>(value: MaybeInvalid<T>): Optional<T>;
|
package/dist/optional.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { isFunction } from "./guard";
|
|
1
|
+
import { useEmpty, useOf } from "./factory";
|
|
2
|
+
import { isFunction, isOptional } from "./guard";
|
|
3
3
|
import { OptionalSymbol } from "./symbol";
|
|
4
4
|
import { invalidate, validate } from "./utility";
|
|
5
5
|
export class Optional {
|
|
@@ -62,15 +62,37 @@ export class Optional {
|
|
|
62
62
|
}
|
|
63
63
|
return new Optional(null);
|
|
64
64
|
}
|
|
65
|
+
flat(mapper) {
|
|
66
|
+
if (this.isPresent() && isFunction(mapper)) {
|
|
67
|
+
let result = mapper(this.value);
|
|
68
|
+
if (isOptional(result)) {
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
throw new TypeError("Must return an Optional.");
|
|
72
|
+
}
|
|
73
|
+
return new Optional(null);
|
|
74
|
+
}
|
|
75
|
+
flatMap(mapper) {
|
|
76
|
+
if (this.isPresent() && isFunction(mapper)) {
|
|
77
|
+
let result = mapper(this.value);
|
|
78
|
+
if (isOptional(result)) {
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
81
|
+
throw new TypeError("Must return an Optional.");
|
|
82
|
+
}
|
|
83
|
+
return new Optional(null);
|
|
84
|
+
}
|
|
85
|
+
orElse(other) {
|
|
86
|
+
if (this.isPresent()) {
|
|
87
|
+
return this.value;
|
|
88
|
+
}
|
|
89
|
+
return other;
|
|
90
|
+
}
|
|
65
91
|
semantic() {
|
|
66
92
|
if (this.isPresent()) {
|
|
67
|
-
return
|
|
68
|
-
return this.value;
|
|
69
|
-
}, () => {
|
|
70
|
-
return this.isEmpty();
|
|
71
|
-
});
|
|
93
|
+
return useOf(this.value);
|
|
72
94
|
}
|
|
73
|
-
return
|
|
95
|
+
return useEmpty();
|
|
74
96
|
}
|
|
75
97
|
static empty() {
|
|
76
98
|
return new Optional(null);
|
package/dist/semantic.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Collector } from "./collector";
|
|
2
|
+
import type { Optional } from "./optional";
|
|
3
3
|
import { type Predicate } from "./utility";
|
|
4
|
-
import type { Generator, Functional, BiFunctional, Consumer, BiConsumer, Comparator, BiPredicate } from "./utility";
|
|
5
|
-
import { WindowCollectable } from "./window";
|
|
4
|
+
import type { Generator, Functional, BiFunctional, Consumer, BiConsumer, Comparator, BiPredicate, Indexed, Supplier, TriFunctional, TriPredicate } from "./utility";
|
|
6
5
|
export declare class Semantic<E> {
|
|
7
6
|
protected generator: Generator<E>;
|
|
8
7
|
protected readonly Semantic: Symbol;
|
|
@@ -44,6 +43,7 @@ export declare class Semantic<E> {
|
|
|
44
43
|
toCollectable(): Collectable<E>;
|
|
45
44
|
toCollectable<C extends Collectable<E>>(mapper: Functional<Generator<E>, C>): C;
|
|
46
45
|
toBigintStatistics(): BigIntStatistics<E>;
|
|
46
|
+
toEvent(): EventCollectable<E>;
|
|
47
47
|
toNumericStatistics(): NumericStatistics<E>;
|
|
48
48
|
toOrdered(): OrderedCollectable<E>;
|
|
49
49
|
toUnordered(): UnorderedCollectable<E>;
|
|
@@ -52,3 +52,203 @@ export declare class Semantic<E> {
|
|
|
52
52
|
translate(offset: bigint): Semantic<E>;
|
|
53
53
|
translate(translator: BiFunctional<E, bigint, bigint>): Semantic<E>;
|
|
54
54
|
}
|
|
55
|
+
export declare abstract class Collectable<E> implements Iterable<E>, AsyncIterable<E> {
|
|
56
|
+
protected readonly Collectable: symbol;
|
|
57
|
+
constructor();
|
|
58
|
+
abstract [Symbol.iterator](): globalThis.Generator<E, void, undefined>;
|
|
59
|
+
abstract [Symbol.asyncIterator](): globalThis.AsyncGenerator<E, void, undefined>;
|
|
60
|
+
anyMatch(predicate: Predicate<E>): boolean;
|
|
61
|
+
allMatch(predicate: Predicate<E>): boolean;
|
|
62
|
+
collect<A, R>(collector: Collector<E, A, R>): R;
|
|
63
|
+
collect<A, R>(identity: Supplier<A>, accumulator: BiFunctional<A, E, A>, finisher: Functional<A, R>): R;
|
|
64
|
+
collect<A, R>(identity: Supplier<A>, accumulator: TriFunctional<A, E, bigint, A>, finisher: Functional<A, R>): R;
|
|
65
|
+
collect<A, R>(identity: Supplier<A>, interruptor: Predicate<E>, accumulator: BiFunctional<A, E, A>, finisher: Functional<A, R>): R;
|
|
66
|
+
collect<A, R>(identity: Supplier<A>, interruptor: BiPredicate<E, bigint>, accumulator: BiFunctional<A, E, A>, finisher: Functional<A, R>): R;
|
|
67
|
+
collect<A, R>(identity: Supplier<A>, interruptor: TriPredicate<E, bigint, A>, accumulator: BiFunctional<A, E, A>, finisher: Functional<A, R>): R;
|
|
68
|
+
collect<A, R>(identity: Supplier<A>, interruptor: Predicate<E>, accumulator: TriFunctional<A, E, bigint, A>, finisher: Functional<A, R>): R;
|
|
69
|
+
collect<A, R>(identity: Supplier<A>, interruptor: BiPredicate<E, bigint>, accumulator: TriFunctional<A, E, bigint, A>, finisher: Functional<A, R>): R;
|
|
70
|
+
collect<A, R>(identity: Supplier<A>, interruptor: TriPredicate<E, bigint, A>, accumulator: TriFunctional<A, E, bigint, A>, finisher: Functional<A, R>): R;
|
|
71
|
+
count(): bigint;
|
|
72
|
+
error(): void;
|
|
73
|
+
error(accumulator: BiFunctional<string, E, string>): void;
|
|
74
|
+
error(accumulator: TriFunctional<string, E, bigint, string>): void;
|
|
75
|
+
error(prefix: string, accumulator: BiFunctional<string, E, string>, suffix: string): void;
|
|
76
|
+
error(prefix: string, accumulator: TriFunctional<string, E, bigint, string>, suffix: string): void;
|
|
77
|
+
isEmpty(): boolean;
|
|
78
|
+
findAny(): Optional<E>;
|
|
79
|
+
findAt(index: number): Optional<E>;
|
|
80
|
+
findAt(index: bigint): Optional<E>;
|
|
81
|
+
findFirst(): Optional<E>;
|
|
82
|
+
findLast(): Optional<E>;
|
|
83
|
+
findMaximum(): Optional<E>;
|
|
84
|
+
findMaximum(comparator: Comparator<E>): Optional<E>;
|
|
85
|
+
findMinimum(): Optional<E>;
|
|
86
|
+
findMinimum(comparator: Comparator<E>): Optional<E>;
|
|
87
|
+
forEach(action: Consumer<E>): void;
|
|
88
|
+
forEach(action: BiConsumer<E, bigint>): void;
|
|
89
|
+
group<K>(classifier: Functional<E, K>): Map<K, Array<E>>;
|
|
90
|
+
group<K>(classifier: BiFunctional<E, bigint, K>): Map<K, Array<E>>;
|
|
91
|
+
groupBy<K, V>(keyExtractor: Functional<E, K>, valueExtractor: Functional<E, V>): Map<K, Array<V>>;
|
|
92
|
+
groupBy<K, V>(keyExtractor: BiFunctional<E, bigint, K>, valueExtractor: BiFunctional<E, bigint, K>): Map<K, Array<V>>;
|
|
93
|
+
join(): string;
|
|
94
|
+
join(delimiter: string): string;
|
|
95
|
+
join(prefix: string, delimiter: string, suffix: string): string;
|
|
96
|
+
join(prefiex: string, accumulator: BiFunctional<string, E, string>, suffix: string): string;
|
|
97
|
+
join(prefiex: string, accumulator: TriFunctional<string, E, bigint, string>, suffix: string): string;
|
|
98
|
+
log(): void;
|
|
99
|
+
log(accumulator: BiFunctional<string, E, string>): void;
|
|
100
|
+
log(accumulator: TriFunctional<string, E, bigint, string>): void;
|
|
101
|
+
log(prefix: string, accumulator: BiFunctional<string, E, string>, suffix: string): void;
|
|
102
|
+
log(prefix: string, accumulator: TriFunctional<string, E, bigint, string>, suffix: string): void;
|
|
103
|
+
nonMatch(predicate: Predicate<E>): boolean;
|
|
104
|
+
nonMatch(predicate: BiPredicate<E, bigint>): boolean;
|
|
105
|
+
partition(count: bigint): Array<Array<E>>;
|
|
106
|
+
partitionBy(classifier: Functional<E, bigint>): Array<Array<E>>;
|
|
107
|
+
partitionBy(classifier: BiFunctional<E, bigint, bigint>): Array<Array<E>>;
|
|
108
|
+
reduce(accumulator: BiFunctional<E, E, E>): Optional<E>;
|
|
109
|
+
reduce(accumulator: TriFunctional<E, E, bigint, E>): Optional<E>;
|
|
110
|
+
reduce(identity: E, accumulator: BiFunctional<E, E, E>): E;
|
|
111
|
+
reduce(identity: E, accumulator: TriFunctional<E, E, bigint, E>): E;
|
|
112
|
+
reduce<R>(identity: R, accumulator: BiFunctional<R, E, R>, finisher: Functional<R, R>): R;
|
|
113
|
+
reduce<R>(identity: R, accumulator: TriFunctional<R, E, bigint, R>, finisher: Functional<R, R>): R;
|
|
114
|
+
semantic(): Semantic<E>;
|
|
115
|
+
abstract source(): Generator<E>;
|
|
116
|
+
toArray(): Array<E>;
|
|
117
|
+
toMap<K, E>(keyExtractor: Functional<E, K>): Map<K, E>;
|
|
118
|
+
toMap<K, V>(keyExtractor: Functional<E, K>, valueExtractor: Functional<E, V>): Map<K, V>;
|
|
119
|
+
toMap<K, V>(keyExtractor: BiFunctional<E, bigint, K>, valueExtractor: BiFunctional<E, bigint, V>): Map<K, V>;
|
|
120
|
+
toSet(): Set<E>;
|
|
121
|
+
write<S = string>(stream: WritableStream<S>): Promise<WritableStream<S>>;
|
|
122
|
+
write<S = string>(stream: WritableStream<S>, accumulator: BiFunctional<WritableStream<S>, E, WritableStream<S>>): Promise<WritableStream<S>>;
|
|
123
|
+
write<S = string>(stream: WritableStream<S>, accumulator: TriFunctional<WritableStream<S>, E, bigint, WritableStream<S>>): Promise<WritableStream<S>>;
|
|
124
|
+
}
|
|
125
|
+
export declare class EventCollectable<E> extends Collectable<E> {
|
|
126
|
+
protected readonly AsyncCollectable: symbol;
|
|
127
|
+
protected generator: Generator<E>;
|
|
128
|
+
constructor(generator: Generator<E>);
|
|
129
|
+
source(): Generator<E>;
|
|
130
|
+
[Symbol.iterator](): globalThis.Generator<E, void, undefined>;
|
|
131
|
+
[Symbol.asyncIterator](): globalThis.AsyncGenerator<E, void, undefined>;
|
|
132
|
+
}
|
|
133
|
+
export declare class UnorderedCollectable<E> extends Collectable<E> {
|
|
134
|
+
protected readonly UnorderedCollectable: symbol;
|
|
135
|
+
protected buffer: Map<bigint, E>;
|
|
136
|
+
constructor(generator: Generator<E>);
|
|
137
|
+
source(): Generator<E>;
|
|
138
|
+
[Symbol.iterator](): globalThis.Generator<E, void, undefined>;
|
|
139
|
+
[Symbol.asyncIterator](): globalThis.AsyncGenerator<E, void, undefined>;
|
|
140
|
+
}
|
|
141
|
+
export declare class OrderedCollectable<E> extends Collectable<E> {
|
|
142
|
+
protected readonly OrderedCollectable: symbol;
|
|
143
|
+
protected buffer: Array<Indexed<E>>;
|
|
144
|
+
constructor(generator: Generator<E>);
|
|
145
|
+
constructor(generator: Generator<E>, comparator: Comparator<E>);
|
|
146
|
+
[Symbol.iterator](): globalThis.Generator<E, void, undefined>;
|
|
147
|
+
[Symbol.asyncIterator](): globalThis.AsyncGenerator<E, void, undefined>;
|
|
148
|
+
source(): Generator<E>;
|
|
149
|
+
isEmpty(): boolean;
|
|
150
|
+
}
|
|
151
|
+
export declare abstract class Statistics<E, D extends number | bigint> extends OrderedCollectable<E> {
|
|
152
|
+
protected readonly Statistics: symbol;
|
|
153
|
+
constructor(generator: Generator<E>);
|
|
154
|
+
constructor(generator: Generator<E>, comparator: Comparator<E>);
|
|
155
|
+
[Symbol.iterator](): globalThis.Generator<E, void, undefined>;
|
|
156
|
+
[Symbol.asyncIterator](): globalThis.AsyncGenerator<E, void, undefined>;
|
|
157
|
+
count(): bigint;
|
|
158
|
+
abstract average(): D;
|
|
159
|
+
abstract average(mapper: Functional<E, D>): D;
|
|
160
|
+
abstract range(): D;
|
|
161
|
+
abstract range(mapper: Functional<E, D>): D;
|
|
162
|
+
abstract variance(): D;
|
|
163
|
+
abstract variance(mapper: Functional<E, D>): D;
|
|
164
|
+
abstract standardDeviation(): D;
|
|
165
|
+
abstract standardDeviation(mapper: Functional<E, D>): D;
|
|
166
|
+
abstract mean(): D;
|
|
167
|
+
abstract mean(mapper: Functional<E, D>): D;
|
|
168
|
+
abstract median(): D;
|
|
169
|
+
abstract median(mapper: Functional<E, D>): D;
|
|
170
|
+
abstract mode(): D;
|
|
171
|
+
abstract mode(mapper: Functional<E, D>): D;
|
|
172
|
+
frequency(): Map<E, bigint>;
|
|
173
|
+
abstract summate(): D;
|
|
174
|
+
abstract summate(mapper: Functional<E, D>): D;
|
|
175
|
+
abstract quantile(quantile: number): D;
|
|
176
|
+
abstract quantile(quantile: number, mapper: Functional<E, D>): D;
|
|
177
|
+
abstract interquartileRange(): D;
|
|
178
|
+
abstract interquartileRange(mapper: Functional<E, D>): D;
|
|
179
|
+
abstract skewness(): D;
|
|
180
|
+
abstract skewness(mapper: Functional<E, D>): D;
|
|
181
|
+
abstract kurtosis(): D;
|
|
182
|
+
abstract kurtosis(mapper: Functional<E, D>): D;
|
|
183
|
+
}
|
|
184
|
+
export declare class NumericStatistics<E> extends Statistics<E, number> {
|
|
185
|
+
protected readonly NumericStatistics: symbol;
|
|
186
|
+
constructor(generator: Generator<E>);
|
|
187
|
+
constructor(generator: Generator<E>, comparator: Comparator<E>);
|
|
188
|
+
[Symbol.iterator](): globalThis.Generator<E, void, undefined>;
|
|
189
|
+
[Symbol.asyncIterator](): globalThis.AsyncGenerator<E, void, undefined>;
|
|
190
|
+
average(): number;
|
|
191
|
+
average(mapper: Functional<E, number>): number;
|
|
192
|
+
range(): number;
|
|
193
|
+
range(mapper: Functional<E, number>): number;
|
|
194
|
+
variance(): number;
|
|
195
|
+
variance(mapper: Functional<E, number>): number;
|
|
196
|
+
standardDeviation(): number;
|
|
197
|
+
standardDeviation(mapper: Functional<E, number>): number;
|
|
198
|
+
mean(): number;
|
|
199
|
+
mean(mapper: Functional<E, number>): number;
|
|
200
|
+
median(): number;
|
|
201
|
+
median(mapper: Functional<E, number>): number;
|
|
202
|
+
mode(): number;
|
|
203
|
+
mode(mapper: Functional<E, number>): number;
|
|
204
|
+
summate(): number;
|
|
205
|
+
summate(mapper: Functional<E, number>): number;
|
|
206
|
+
quantile(quantile: number): number;
|
|
207
|
+
quantile(quantile: number, mapper: Functional<E, number>): number;
|
|
208
|
+
interquartileRange(): number;
|
|
209
|
+
interquartileRange(mapper: Functional<E, number>): number;
|
|
210
|
+
skewness(): number;
|
|
211
|
+
skewness(mapper: Functional<E, number>): number;
|
|
212
|
+
kurtosis(): number;
|
|
213
|
+
kurtosis(mapper: Functional<E, number>): number;
|
|
214
|
+
}
|
|
215
|
+
export declare class BigIntStatistics<E> extends Statistics<E, bigint> {
|
|
216
|
+
protected readonly BigIntStatistics: symbol;
|
|
217
|
+
constructor(generator: Generator<E>);
|
|
218
|
+
constructor(generator: Generator<E>, comparator: Comparator<E>);
|
|
219
|
+
[Symbol.iterator](): globalThis.Generator<E, void, undefined>;
|
|
220
|
+
[Symbol.asyncIterator](): globalThis.AsyncGenerator<E, void, undefined>;
|
|
221
|
+
average(): bigint;
|
|
222
|
+
average(mapper: Functional<E, bigint>): bigint;
|
|
223
|
+
range(): bigint;
|
|
224
|
+
range(mapper: Functional<E, bigint>): bigint;
|
|
225
|
+
variance(): bigint;
|
|
226
|
+
variance(mapper: Functional<E, bigint>): bigint;
|
|
227
|
+
standardDeviation(): bigint;
|
|
228
|
+
standardDeviation(mapper: Functional<E, bigint>): bigint;
|
|
229
|
+
mean(): bigint;
|
|
230
|
+
mean(mapper: Functional<E, bigint>): bigint;
|
|
231
|
+
median(): bigint;
|
|
232
|
+
median(mapper: Functional<E, bigint>): bigint;
|
|
233
|
+
mode(): bigint;
|
|
234
|
+
mode(mapper: Functional<E, bigint>): bigint;
|
|
235
|
+
summate(): bigint;
|
|
236
|
+
summate(mapper: Functional<E, bigint>): bigint;
|
|
237
|
+
quantile(quantile: number): bigint;
|
|
238
|
+
quantile(quantile: number, mapper: Functional<E, bigint>): bigint;
|
|
239
|
+
interquartileRange(): bigint;
|
|
240
|
+
interquartileRange(mapper: Functional<E, bigint>): bigint;
|
|
241
|
+
skewness(): bigint;
|
|
242
|
+
skewness(mapper: Functional<E, bigint>): bigint;
|
|
243
|
+
kurtosis(): bigint;
|
|
244
|
+
kurtosis(mapper: Functional<E, bigint>): bigint;
|
|
245
|
+
}
|
|
246
|
+
export declare class WindowCollectable<E> extends OrderedCollectable<E> {
|
|
247
|
+
protected readonly WindowCollectable: symbol;
|
|
248
|
+
constructor(generator: Generator<E>);
|
|
249
|
+
constructor(generator: Generator<E>, comparator: Comparator<E>);
|
|
250
|
+
[Symbol.iterator](): globalThis.Generator<E, void, undefined>;
|
|
251
|
+
[Symbol.asyncIterator](): globalThis.AsyncGenerator<E, void, undefined>;
|
|
252
|
+
slide(size: bigint, step?: bigint): Semantic<Semantic<E>>;
|
|
253
|
+
tumble(size: bigint): Semantic<Semantic<E>>;
|
|
254
|
+
}
|