semantic-typescript 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/dist/asynchronous/collector.d.ts +231 -0
  2. package/dist/asynchronous/collector.js +800 -0
  3. package/dist/asynchronous/semantic.d.ts +257 -0
  4. package/dist/asynchronous/semantic.js +1853 -0
  5. package/dist/factory.d.ts +110 -32
  6. package/dist/factory.js +582 -189
  7. package/dist/guard.d.ts +24 -27
  8. package/dist/guard.js +37 -43
  9. package/dist/hook.d.ts +11 -7
  10. package/dist/hook.js +74 -21
  11. package/dist/index.d.ts +2 -3
  12. package/dist/index.js +2 -3
  13. package/dist/optional.d.ts +5 -5
  14. package/dist/optional.js +14 -10
  15. package/dist/symbol.d.ts +19 -23
  16. package/dist/symbol.js +19 -23
  17. package/dist/synchronous/collector.d.ts +232 -0
  18. package/dist/{collector.js → synchronous/collector.js} +160 -170
  19. package/dist/{collectable.d.ts → synchronous/semantic.d.ts} +114 -71
  20. package/dist/{collectable.js → synchronous/semantic.js} +761 -294
  21. package/dist/utility.d.ts +8 -2
  22. package/dist/utility.js +1 -0
  23. package/package.json +1 -1
  24. package/readme.cn.md +158 -697
  25. package/readme.de.md +163 -432
  26. package/readme.es.md +163 -433
  27. package/readme.fr.md +162 -444
  28. package/readme.jp.md +162 -442
  29. package/readme.kr.md +161 -430
  30. package/readme.md +157 -799
  31. package/readme.ru.md +161 -426
  32. package/readme.tw.md +161 -436
  33. package/dist/collector.d.ts +0 -245
  34. package/dist/map.d.ts +0 -76
  35. package/dist/map.js +0 -253
  36. package/dist/node.d.ts +0 -182
  37. package/dist/node.js +0 -918
  38. package/dist/semantic.d.ts +0 -52
  39. package/dist/semantic.js +0 -504
  40. package/dist/set.d.ts +0 -19
  41. package/dist/set.js +0 -65
  42. package/dist/statistics.d.ts +0 -97
  43. package/dist/statistics.js +0 -483
  44. package/dist/tree.d.ts +0 -82
  45. package/dist/tree.js +0 -257
  46. package/dist/window.d.ts +0 -12
  47. package/dist/window.js +0 -72
@@ -1,52 +0,0 @@
1
- import { BigIntStatistics, Collectable, NumericStatistics, OrderedCollectable, UnorderedCollectable, WindowCollectable } from "./collectable";
2
- import { type Predicate } from "./utility";
3
- import type { Generator, Functional, BiFunctional, Consumer, BiConsumer, Comparator, BiPredicate } from "./utility";
4
- export declare class Semantic<E> {
5
- protected generator: Generator<E>;
6
- protected readonly Semantic: Symbol;
7
- constructor(generator: Generator<E>);
8
- concat(other: Semantic<E>): Semantic<E>;
9
- concat(other: Iterable<E>): Semantic<E>;
10
- distinct(): Semantic<E>;
11
- distinct<K>(keyExtractor: Functional<E, K>): Semantic<E>;
12
- distinct<K>(keyExtractor: BiFunctional<E, bigint, K>): Semantic<E>;
13
- dropWhile(predicate: Predicate<E>): Semantic<E>;
14
- dropWhile(predicate: BiPredicate<E, bigint>): Semantic<E>;
15
- filter(predicate: Predicate<E>): Semantic<E>;
16
- filter(predicate: BiPredicate<E, bigint>): Semantic<E>;
17
- flat(mapper: Functional<E, Iterable<E>>): Semantic<E>;
18
- flat(mapper: BiFunctional<E, bigint, Iterable<E>>): Semantic<E>;
19
- flat(mapper: Functional<E, Semantic<E>>): Semantic<E>;
20
- flat(mapper: BiFunctional<E, bigint, Semantic<E>>): Semantic<E>;
21
- flatMap<R>(mapper: Functional<E, Iterable<R>>): Semantic<R>;
22
- flatMap<R>(mapper: BiFunctional<E, bigint, Iterable<R>>): Semantic<R>;
23
- flatMap<R>(mapper: Functional<E, Semantic<R>>): Semantic<R>;
24
- flatMap<R>(mapper: BiFunctional<E, bigint, Semantic<R>>): Semantic<R>;
25
- limit(n: number): Semantic<E>;
26
- limit(n: bigint): Semantic<E>;
27
- map<R>(mapper: Functional<E, R>): Semantic<R>;
28
- map<R>(mapper: BiFunctional<E, bigint, R>): Semantic<R>;
29
- peek(consumer: Consumer<E>): Semantic<E>;
30
- peek(consumer: BiConsumer<E, bigint>): Semantic<E>;
31
- redirect(redirector: BiFunctional<E, bigint, bigint>): Semantic<E>;
32
- reverse(): Semantic<E>;
33
- shuffle(): Semantic<E>;
34
- shuffle(mapper: BiFunctional<E, bigint, bigint>): Semantic<E>;
35
- skip(n: number): Semantic<E>;
36
- skip(n: bigint): Semantic<E>;
37
- sorted(): OrderedCollectable<E>;
38
- sorted(comparator: Comparator<E>): OrderedCollectable<E>;
39
- sub(start: bigint, end: bigint): Semantic<E>;
40
- takeWhile(predicate: Predicate<E>): Semantic<E>;
41
- takeWhile(predicate: BiPredicate<E, bigint>): Semantic<E>;
42
- toCollectable(): Collectable<E>;
43
- toCollectable<C extends Collectable<E>>(mapper: Functional<Generator<E>, C>): C;
44
- toBigintStatistics(): BigIntStatistics<E>;
45
- toNumericStatistics(): NumericStatistics<E>;
46
- toOrdered(): OrderedCollectable<E>;
47
- toUnordered(): UnorderedCollectable<E>;
48
- toWindow(): WindowCollectable<E>;
49
- translate(offset: number): Semantic<E>;
50
- translate(offset: bigint): Semantic<E>;
51
- translate(translator: BiFunctional<E, bigint, bigint>): Semantic<E>;
52
- }
package/dist/semantic.js DELETED
@@ -1,504 +0,0 @@
1
- import { BigIntStatistics, Collectable, NumericStatistics, OrderedCollectable, UnorderedCollectable, WindowCollectable } from "./collectable";
2
- import { isBigInt, isCollectable, isFunction, isIterable, isNumber, isSemantic } from "./guard";
3
- import { useHash } from "./hash";
4
- import { useCompare } from "./hook";
5
- import { SemanticSymbol } from "./symbol";
6
- import { validate } from "./utility";
7
- export class Semantic {
8
- generator;
9
- Semantic = SemanticSymbol;
10
- constructor(generator) {
11
- this.generator = generator;
12
- Object.defineProperties(this, {
13
- "Semantic": {
14
- value: SemanticSymbol,
15
- writable: false,
16
- enumerable: false,
17
- configurable: false
18
- },
19
- "generator": {
20
- value: generator,
21
- writable: false,
22
- enumerable: false,
23
- configurable: false
24
- }
25
- });
26
- Object.freeze(this);
27
- }
28
- concat(other) {
29
- if (isSemantic(other)) {
30
- return new Semantic((accept, interrupt) => {
31
- try {
32
- let count = 0n;
33
- this.generator((element, index) => {
34
- accept(element, index);
35
- count++;
36
- }, interrupt);
37
- let otherGenerator = Reflect.has(other, "generator") ? Reflect.get(other, "generator") : () => { };
38
- otherGenerator((element, index) => {
39
- accept(element, index + count);
40
- }, interrupt);
41
- }
42
- catch (error) {
43
- throw new Error("Uncaught error on concatenation.");
44
- }
45
- });
46
- }
47
- if (isIterable(other)) {
48
- return new Semantic((accept, interrupt) => {
49
- try {
50
- let count = 0n;
51
- this.generator((element, index) => {
52
- accept(element, index);
53
- count++;
54
- }, interrupt);
55
- for (let element of other) {
56
- accept(element, count);
57
- count++;
58
- }
59
- }
60
- catch (error) {
61
- throw new Error("Uncaught error on concatenation.");
62
- }
63
- });
64
- }
65
- throw new TypeError("Invalid arguments.");
66
- }
67
- distinct(argument1) {
68
- let keyExtractor = validate(argument1) ? argument1 : (element) => element;
69
- return new Semantic((accept, interrupt) => {
70
- try {
71
- let set = new Set();
72
- this.generator((element, index) => {
73
- let key = keyExtractor(element, index);
74
- if (!set.has(key)) {
75
- set.add(key);
76
- accept(element, index);
77
- }
78
- }, interrupt);
79
- }
80
- catch (error) {
81
- throw new Error("Uncaught error on distinct.");
82
- }
83
- });
84
- }
85
- dropWhile(predicate) {
86
- if (isFunction(predicate)) {
87
- return new Semantic((accept, interrupt) => {
88
- try {
89
- let dropping = true;
90
- this.generator((element, index) => {
91
- if (dropping) {
92
- if (!predicate(element, index)) {
93
- dropping = false;
94
- accept(element, index);
95
- }
96
- return;
97
- }
98
- accept(element, index);
99
- }, interrupt);
100
- }
101
- catch (error) {
102
- throw new Error("Uncaught error on dropWhile.");
103
- }
104
- });
105
- }
106
- throw new TypeError("Invalid arguments.");
107
- }
108
- filter(predicate) {
109
- if (isFunction(predicate)) {
110
- return new Semantic((accept, interrupt) => {
111
- try {
112
- this.generator((element, index) => {
113
- if (predicate(element, index)) {
114
- accept(element, index);
115
- }
116
- }, interrupt);
117
- }
118
- catch (error) {
119
- throw new Error("Uncaught error on filter.");
120
- }
121
- });
122
- }
123
- throw new TypeError("Invalid arguments.");
124
- }
125
- flat(mapper) {
126
- if (isFunction(mapper)) {
127
- return new Semantic((accept, interrupt) => {
128
- try {
129
- let count = 0n;
130
- let stop = false;
131
- this.generator((element, index) => {
132
- let result = mapper(element, index);
133
- if (isIterable(result)) {
134
- for (let subElement of result) {
135
- accept(subElement, count);
136
- stop = stop || interrupt(subElement, count);
137
- count++;
138
- }
139
- }
140
- else if (isSemantic(result)) {
141
- result.generator((subElement) => {
142
- accept(subElement, count);
143
- stop = stop || interrupt(subElement, count);
144
- count++;
145
- }, (element) => interrupt(element, count) || stop);
146
- }
147
- }, (element) => interrupt(element, count) || stop);
148
- }
149
- catch (error) {
150
- throw new Error("Uncaught error on flat.");
151
- }
152
- });
153
- }
154
- throw new TypeError("Invalid arguments.");
155
- }
156
- flatMap(mapper) {
157
- if (isFunction(mapper)) {
158
- return new Semantic((accept, interrupt) => {
159
- try {
160
- let count = 0n;
161
- let stop = false;
162
- this.generator((element, index) => {
163
- let result = mapper(element, index);
164
- if (isIterable(result)) {
165
- for (let subElement of result) {
166
- accept(subElement, count);
167
- stop = stop || interrupt(subElement, count);
168
- count++;
169
- }
170
- }
171
- else if (isSemantic(result)) {
172
- result.generator((subElement) => {
173
- accept(subElement, count);
174
- stop = stop || interrupt(subElement, count);
175
- count++;
176
- }, (element) => interrupt(element, count) || stop);
177
- }
178
- }, () => stop);
179
- }
180
- catch (error) {
181
- throw new Error("Uncaught error on flatMap.");
182
- }
183
- });
184
- }
185
- throw new TypeError("Invalid arguments.");
186
- }
187
- limit(n) {
188
- if (isNumber(n)) {
189
- let limit = BigInt(n);
190
- return new Semantic((accept, interrupt) => {
191
- try {
192
- let count = 0n;
193
- this.generator((element, index) => {
194
- if (count < limit) {
195
- accept(element, index);
196
- count++;
197
- }
198
- }, (element) => interrupt(element, count) || count >= limit);
199
- }
200
- catch (error) {
201
- throw new Error("Uncaught error on limit.");
202
- }
203
- });
204
- }
205
- if (isBigInt(n)) {
206
- let limit = n;
207
- return new Semantic((accept, interrupt) => {
208
- try {
209
- let count = 0n;
210
- this.generator((element, index) => {
211
- if (count < limit) {
212
- accept(element, index);
213
- count++;
214
- }
215
- }, (element) => interrupt(element, count) || count >= limit);
216
- }
217
- catch (error) {
218
- throw new Error("Uncaught error on limit.");
219
- }
220
- });
221
- }
222
- throw new TypeError("Invalid arguments.");
223
- }
224
- map(mapper) {
225
- if (isFunction(mapper)) {
226
- return new Semantic((accept, interrupt) => {
227
- try {
228
- let stop = false;
229
- this.generator((element, index) => {
230
- let resolved = mapper(element, index);
231
- accept(resolved, index);
232
- stop = stop || interrupt(resolved, index);
233
- }, () => stop);
234
- }
235
- catch (error) {
236
- throw new Error("Uncaught error on map.");
237
- }
238
- });
239
- }
240
- throw new TypeError("Invalid arguments.");
241
- }
242
- peek(consumer) {
243
- if (isFunction(consumer)) {
244
- return new Semantic((accept, interrupt) => {
245
- try {
246
- this.generator((element, index) => {
247
- accept(element, index);
248
- consumer(element, index);
249
- }, interrupt);
250
- }
251
- catch (error) {
252
- throw new Error("Uncaught error on peek.");
253
- }
254
- });
255
- }
256
- throw new TypeError("Invalid arguments.");
257
- }
258
- redirect(redirector) {
259
- if (isFunction(redirector)) {
260
- return new Semantic((accept, interrupt) => {
261
- try {
262
- this.generator((element, index) => {
263
- accept(element, redirector(element, index));
264
- }, interrupt);
265
- }
266
- catch (error) {
267
- throw new Error("Uncaught error on redirect.");
268
- }
269
- });
270
- }
271
- throw new TypeError("Invalid arguments.");
272
- }
273
- reverse() {
274
- return new Semantic((accept, interrupt) => {
275
- try {
276
- this.generator((element, index) => {
277
- accept(element, -index);
278
- }, interrupt);
279
- }
280
- catch (error) {
281
- throw new Error("Uncaught error on reverse.");
282
- }
283
- });
284
- }
285
- shuffle(mapper) {
286
- if (isFunction(mapper)) {
287
- try {
288
- return new Semantic((accept, interrupt) => {
289
- this.generator((element, index) => {
290
- accept(element, mapper(element, index));
291
- }, interrupt);
292
- });
293
- }
294
- catch (error) {
295
- throw new Error("Uncaught error on shuffle.");
296
- }
297
- }
298
- return new Semantic((accept, interrupt) => {
299
- try {
300
- this.generator((element, index) => {
301
- accept(element, useHash(element, index));
302
- }, interrupt);
303
- }
304
- catch (error) {
305
- throw new Error("Uncaught error on shuffle.");
306
- }
307
- });
308
- }
309
- skip(n) {
310
- if (isNumber(n)) {
311
- return new Semantic((accept, interrupt) => {
312
- try {
313
- let count = 0n;
314
- let limit = BigInt(n);
315
- this.generator((element, index) => {
316
- if (count < limit) {
317
- count++;
318
- }
319
- else {
320
- accept(element, index);
321
- }
322
- }, interrupt);
323
- }
324
- catch (error) {
325
- throw new Error("Uncaught error on skip.");
326
- }
327
- });
328
- }
329
- if (isBigInt(n)) {
330
- return new Semantic((accept, interrupt) => {
331
- try {
332
- let count = 0n;
333
- this.generator((element, index) => {
334
- if (count < n) {
335
- count++;
336
- }
337
- else {
338
- accept(element, index);
339
- }
340
- }, interrupt);
341
- }
342
- catch (error) {
343
- throw new Error("Uncaught error on skip.");
344
- }
345
- });
346
- }
347
- throw new TypeError("Invalid arguments.");
348
- }
349
- sorted(comparator) {
350
- if (isFunction(comparator)) {
351
- try {
352
- return new OrderedCollectable(this.generator, comparator);
353
- }
354
- catch (error) {
355
- throw new Error("Uncaught error on sorted.");
356
- }
357
- }
358
- try {
359
- return new OrderedCollectable(this.generator, (a, b) => useCompare(a, b));
360
- }
361
- catch (error) {
362
- throw new Error("Uncaught error on sorted.");
363
- }
364
- }
365
- sub(start, end) {
366
- return new Semantic((accept, interrupt) => {
367
- try {
368
- let count = 0n;
369
- this.generator((element, index) => {
370
- if (count < end) {
371
- count++;
372
- if (count >= start) {
373
- accept(element, index);
374
- }
375
- }
376
- }, interrupt);
377
- }
378
- catch (error) {
379
- throw new Error("Uncaught error on sub.");
380
- }
381
- });
382
- }
383
- takeWhile(predicate) {
384
- return new Semantic((accept, interrupt) => {
385
- try {
386
- this.generator((element, index) => {
387
- if (!predicate(element, index)) {
388
- interrupt(element, index);
389
- return;
390
- }
391
- accept(element, index);
392
- }, interrupt);
393
- }
394
- catch (error) {
395
- throw new Error("Uncaught error on takeWhile.");
396
- }
397
- });
398
- }
399
- toCollectable(mapper) {
400
- if (isFunction(mapper)) {
401
- try {
402
- let collectable = mapper(this.generator);
403
- if (isCollectable(collectable)) {
404
- return collectable;
405
- }
406
- }
407
- catch (error) {
408
- throw new Error("Uncaught error on toCollectable.");
409
- }
410
- }
411
- try {
412
- return new UnorderedCollectable(this.generator);
413
- }
414
- catch (error) {
415
- throw new Error("Uncaught error on toCollectable.");
416
- }
417
- }
418
- toBigintStatistics() {
419
- try {
420
- return new BigIntStatistics(this.generator);
421
- }
422
- catch (error) {
423
- throw new Error("Uncaught error on toBigintStatistics.");
424
- }
425
- }
426
- toNumericStatistics() {
427
- try {
428
- return new NumericStatistics(this.generator);
429
- }
430
- catch (error) {
431
- throw new Error("Uncaught error on toNumericStatistics.");
432
- }
433
- }
434
- toOrdered() {
435
- try {
436
- return new OrderedCollectable(this.generator);
437
- }
438
- catch (error) {
439
- throw new Error("Uncaught error on toOrdered.");
440
- }
441
- }
442
- toUnordered() {
443
- try {
444
- return new UnorderedCollectable(this.generator);
445
- }
446
- catch (error) {
447
- throw new Error("Uncaught error on toUnordered.");
448
- }
449
- }
450
- toWindow() {
451
- try {
452
- return new WindowCollectable(this.generator);
453
- }
454
- catch (error) {
455
- throw new Error("Uncaught error on toWindow.");
456
- }
457
- }
458
- translate(argument1) {
459
- if (isNumber(argument1)) {
460
- let offset = argument1;
461
- return new Semantic((accept, interrupt) => {
462
- try {
463
- this.generator((element, index) => {
464
- accept(element, index + BigInt(offset));
465
- }, interrupt);
466
- }
467
- catch (error) {
468
- throw new Error("Uncaught error on translate.");
469
- }
470
- });
471
- }
472
- else if (isBigInt(argument1)) {
473
- let offset = argument1;
474
- return new Semantic((accept, interrupt) => {
475
- try {
476
- this.generator((element, index) => {
477
- accept(element, index + offset);
478
- }, interrupt);
479
- }
480
- catch (error) {
481
- throw new Error("Uncaught error on translate.");
482
- }
483
- });
484
- }
485
- else if (isFunction(argument1)) {
486
- let translator = argument1;
487
- return new Semantic((accept, interrupt) => {
488
- try {
489
- this.generator((element, index) => {
490
- accept(element, index + translator(element, index));
491
- }, interrupt);
492
- }
493
- catch (error) {
494
- throw new Error("Uncaught error on translate.");
495
- }
496
- });
497
- }
498
- throw new TypeError("Invalid arguments.");
499
- }
500
- }
501
- ;
502
- Object.freeze(Semantic);
503
- Object.freeze(Semantic.prototype);
504
- Object.freeze(Object.getPrototypeOf(Semantic));
package/dist/set.d.ts DELETED
@@ -1,19 +0,0 @@
1
- import { HashMap } from "./map";
2
- import type { BiConsumer, Consumer, TriConsumer } from "./utility";
3
- export declare class HashSet<E> implements Set<E> {
4
- protected map: HashMap<E, boolean>;
5
- size: number;
6
- constructor();
7
- add(value: E): this;
8
- clear(): void;
9
- delete(value: E): boolean;
10
- entries(): SetIterator<[E, E]>;
11
- forEach(consumer: Consumer<E>): void;
12
- forEach(consumer: BiConsumer<E, E>): void;
13
- forEach(consumer: TriConsumer<E, E, Set<E>>): void;
14
- has(value: E): boolean;
15
- keys(): IterableIterator<E>;
16
- values(): IterableIterator<E>;
17
- [Symbol.iterator](): IterableIterator<E>;
18
- [Symbol.toStringTag]: string;
19
- }
package/dist/set.js DELETED
@@ -1,65 +0,0 @@
1
- import { HashMap } from "./map";
2
- export class HashSet {
3
- map = new HashMap();
4
- size = 0;
5
- constructor() {
6
- Object.defineProperty(this, "size", {
7
- get: () => this.map.size,
8
- set: (value) => {
9
- this.map.size = value;
10
- },
11
- enumerable: true,
12
- configurable: true
13
- });
14
- Object.freeze(this);
15
- }
16
- add(value) {
17
- this.map.set(value, true);
18
- return this;
19
- }
20
- clear() {
21
- this.map.clear();
22
- }
23
- delete(value) {
24
- return this.map.delete(value);
25
- }
26
- *entries() {
27
- for (let [key, value] of this.map.entries()) {
28
- if (value) {
29
- yield [key, key];
30
- }
31
- }
32
- }
33
- forEach(consumer) {
34
- for (let [key, value] of this.map.entries()) {
35
- if (value) {
36
- consumer(key, key);
37
- }
38
- }
39
- }
40
- has(value) {
41
- return this.map.has(value);
42
- }
43
- *keys() {
44
- for (let [key, value] of this.map.entries()) {
45
- if (value) {
46
- yield key;
47
- }
48
- }
49
- }
50
- *values() {
51
- for (let [key, value] of this.map.entries()) {
52
- if (value) {
53
- yield key;
54
- }
55
- }
56
- }
57
- [Symbol.iterator]() {
58
- return this.values();
59
- }
60
- [Symbol.toStringTag] = "HashSet";
61
- }
62
- ;
63
- Object.freeze(HashSet);
64
- Object.freeze(HashSet.prototype);
65
- Object.freeze(Object.getPrototypeOf(HashSet));