semantic-typescript 0.3.7 → 0.4.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.
package/dist/collector.js CHANGED
@@ -1,6 +1,8 @@
1
1
  import { isBigInt, isBoolean, isCollectable, isFunction, isIterable, isNumber, isObject, isSemantic, isString } from "./guard";
2
2
  import { useCompare, useToBigInt, useToNumber } from "./hook";
3
+ import { HashMap } from "./map";
3
4
  import { Optional } from "./optional";
5
+ import { HashSet } from "./set";
4
6
  import { CollectableSymbol } from "./symbol";
5
7
  import { validate, invalidate } from "./utility";
6
8
  export class Collector {
@@ -9,12 +11,45 @@ export class Collector {
9
11
  accumulator;
10
12
  finisher;
11
13
  Collector = CollectableSymbol;
12
- constructor(identity, interruptor, accumulator, finisher) {
13
- if (isFunction(identity) && isFunction(interruptor) && isFunction(accumulator) && isFunction(finisher)) {
14
+ constructor(identity, interrupt, accumulator, finisher) {
15
+ if (isFunction(identity) && isFunction(interrupt) && isFunction(accumulator) && isFunction(finisher)) {
14
16
  this.identity = identity;
15
- this.interrupt = interruptor;
17
+ this.interrupt = interrupt;
16
18
  this.accumulator = accumulator;
17
19
  this.finisher = finisher;
20
+ Object.defineProperties(this, {
21
+ "identity": {
22
+ value: identity,
23
+ writable: false,
24
+ enumerable: true,
25
+ configurable: false
26
+ },
27
+ "interrupt": {
28
+ value: interrupt,
29
+ writable: false,
30
+ enumerable: true,
31
+ configurable: false
32
+ },
33
+ "accumulator": {
34
+ value: accumulator,
35
+ writable: false,
36
+ enumerable: true,
37
+ configurable: false
38
+ },
39
+ "finisher": {
40
+ value: finisher,
41
+ writable: false,
42
+ enumerable: true,
43
+ configurable: false
44
+ },
45
+ "Collector": {
46
+ value: CollectableSymbol,
47
+ writable: false,
48
+ enumerable: false,
49
+ configurable: false
50
+ }
51
+ });
52
+ Object.freeze(this);
18
53
  }
19
54
  else {
20
55
  throw new TypeError("Invalid arguments");
@@ -93,20 +128,22 @@ export class Collector {
93
128
  static full(identity, accumulator, finisher) {
94
129
  return new Collector(identity, () => false, accumulator, finisher);
95
130
  }
96
- static shortable(identity, interruptor, accumulator, finisher) {
97
- return new Collector(identity, interruptor, accumulator, finisher);
131
+ static shortable(identity, interrupt, accumulator, finisher) {
132
+ return new Collector(identity, interrupt, accumulator, finisher);
98
133
  }
99
134
  }
100
135
  ;
136
+ ;
101
137
  export let useAnyMatch = (predicate) => {
102
138
  if (isFunction(predicate)) {
103
- return Collector.shortable(() => false, (_element, _index, accumulator) => isBoolean(accumulator) && accumulator, (accumulator, element) => accumulator || predicate(element), (accumulator) => accumulator);
139
+ return Collector.shortable(() => false, (_element, _index, accumulator) => isBoolean(accumulator) && accumulator, (accumulator, element, index) => accumulator || predicate(element, index), (accumulator) => accumulator);
104
140
  }
105
141
  throw new TypeError("Predicate must be a function.");
106
142
  };
143
+ ;
107
144
  export let useAllMatch = (predicate) => {
108
145
  if (isFunction(predicate)) {
109
- return Collector.shortable(() => true, (_element, _index, accumulator) => isBoolean(accumulator) && !accumulator, (accumulator, element) => accumulator && predicate(element), (accumulator) => accumulator);
146
+ return Collector.shortable(() => true, (_element, _index, accumulator) => isBoolean(accumulator) && !accumulator, (accumulator, element, index) => accumulator && predicate(element, index), (accumulator) => accumulator);
110
147
  }
111
148
  throw new TypeError("Predicate must be a function.");
112
149
  };
@@ -165,6 +202,31 @@ export let useError = (argument1, argument2, argument3) => {
165
202
  });
166
203
  }
167
204
  };
205
+ ;
206
+ export let useFindAt = (index) => {
207
+ let target = useToBigInt(index);
208
+ if (target < 0n) {
209
+ return Collector.full(() => [], (accumulator, element) => {
210
+ accumulator.push(element);
211
+ return accumulator;
212
+ }, (accumulator) => {
213
+ if (accumulator.length === 0) {
214
+ return Optional.empty();
215
+ }
216
+ let limited = (((BigInt(accumulator.length)) % target) + target) % target;
217
+ return Optional.ofNullable(accumulator[Number(limited)]);
218
+ });
219
+ }
220
+ return Collector.shortable(() => [], (_element, _index, accumulator) => BigInt(accumulator.length) - 1n === target, (accumulator, element) => {
221
+ accumulator.push(element);
222
+ return accumulator;
223
+ }, (accumulator) => {
224
+ if (accumulator.length === 0) {
225
+ return Optional.empty();
226
+ }
227
+ return Optional.ofNullable(accumulator[Number(target)]);
228
+ });
229
+ };
168
230
  export let useFindFirst = () => {
169
231
  return Collector.shortable(() => Optional.empty(), (_element, _index, accumulator) => validate(accumulator) && accumulator.isPresent(), (accumulator, element) => {
170
232
  if (validate(accumulator) && accumulator.isPresent()) {
@@ -215,16 +277,18 @@ export let useForEach = (action) => {
215
277
  }
216
278
  throw new TypeError("Action must be a function.");
217
279
  };
280
+ ;
218
281
  export let useNoneMatch = (predicate) => {
219
282
  if (isFunction(predicate)) {
220
- return Collector.shortable(() => true, (_element, _index, accumulator) => !accumulator, (accumulator, element) => accumulator && !predicate(element), (accumulator) => !accumulator);
283
+ return Collector.shortable(() => true, (_element, _index, accumulator) => !accumulator, (accumulator, element, index) => accumulator && !predicate(element, index), (accumulator) => !accumulator);
221
284
  }
222
285
  throw new TypeError("Predicate must be a function.");
223
286
  };
287
+ ;
224
288
  export let useGroup = (classifier) => {
225
289
  if (isFunction(classifier)) {
226
- return Collector.full(() => new Map(), (accumulator, element) => {
227
- let key = classifier(element);
290
+ return Collector.full(() => new Map(), (accumulator, element, index) => {
291
+ let key = classifier(element, index);
228
292
  let group = accumulator.get(key) || [];
229
293
  group.push(element);
230
294
  accumulator.set(key, group);
@@ -235,10 +299,10 @@ export let useGroup = (classifier) => {
235
299
  };
236
300
  export let useGroupBy = (keyExtractor, valueExtractor) => {
237
301
  if (isFunction(keyExtractor) && isFunction(valueExtractor)) {
238
- return Collector.full(() => new Map(), (accumulator, element) => {
239
- let key = keyExtractor(element);
302
+ return Collector.full(() => new Map(), (accumulator, element, index) => {
303
+ let key = keyExtractor(element, index);
240
304
  let group = accumulator.get(key) || [];
241
- group.push(valueExtractor(element));
305
+ group.push(valueExtractor(element, index));
242
306
  accumulator.set(key, group);
243
307
  return accumulator;
244
308
  }, (accumulator) => accumulator);
@@ -322,13 +386,14 @@ export let usePartition = (count) => {
322
386
  }
323
387
  throw new TypeError("Count must be a BigInt.");
324
388
  };
389
+ ;
325
390
  export let usePartitionBy = (classifier) => {
326
391
  if (isFunction(classifier)) {
327
392
  return Collector.full(() => {
328
393
  return [];
329
- }, (array, element) => {
330
- let index = classifier(element);
331
- while (index > BigInt(array.length) - 1n) {
394
+ }, (array, element, index) => {
395
+ let resolved = classifier(element, index);
396
+ while (resolved > BigInt(array.length) - 1n) {
332
397
  array.push([]);
333
398
  }
334
399
  array[Number(index)].push(element);
@@ -374,11 +439,24 @@ export let useToArray = () => {
374
439
  return array;
375
440
  }, (array) => array);
376
441
  };
442
+ ;
377
443
  export let useToMap = (keyExtractor, valueExtractor) => {
378
444
  if (isFunction(keyExtractor) && isFunction(valueExtractor)) {
379
- return Collector.full(() => new Map(), (map, element) => {
380
- let key = keyExtractor(element);
381
- let value = valueExtractor(element);
445
+ return Collector.full(() => new Map(), (map, element, index) => {
446
+ let key = keyExtractor(element, index);
447
+ let value = valueExtractor(element, index);
448
+ map.set(key, value);
449
+ return map;
450
+ }, (map) => map);
451
+ }
452
+ throw new TypeError("Key extractor and value extractor must be functions.");
453
+ };
454
+ ;
455
+ export let useToHashMap = (keyExtractor, valueExtractor) => {
456
+ if (isFunction(keyExtractor) && isFunction(valueExtractor)) {
457
+ return Collector.full(() => new HashMap(), (map, element, index) => {
458
+ let key = keyExtractor(element, index);
459
+ let value = valueExtractor(element, index);
382
460
  map.set(key, value);
383
461
  return map;
384
462
  }, (map) => map);
@@ -391,6 +469,12 @@ export let useToSet = () => {
391
469
  return set;
392
470
  }, (set) => set);
393
471
  };
472
+ export let useToHashSet = () => {
473
+ return Collector.full(() => new HashSet(), (set, element) => {
474
+ set.add(element);
475
+ return set;
476
+ }, (set) => set);
477
+ };
394
478
  ;
395
479
  export let useWrite = (argument1, argument2) => {
396
480
  if (isObject(argument1)) {
package/dist/factory.d.ts CHANGED
@@ -9,7 +9,11 @@ export declare let attribute: <T extends object>(target: T) => Semantic<Attribut
9
9
  export declare let blob: Functional<Blob, Semantic<Uint8Array>> & BiFunctional<Blob, bigint, Semantic<Uint8Array>>;
10
10
  export declare let empty: <E>() => Semantic<E>;
11
11
  export declare let fill: (<E>(element: E, count: bigint) => Semantic<E>) & (<E>(supplier: Supplier<E>, count: bigint) => Semantic<E>);
12
- export declare let from: <E>(iterable: Iterable<E>) => Semantic<E>;
12
+ export interface From {
13
+ <E>(iterable: Iterable<E>): Semantic<E>;
14
+ <E>(iterable: AsyncIterable<E>): Semantic<E>;
15
+ }
16
+ export declare let from: From;
13
17
  export declare let generate: (<E>(supplier: Supplier<E>, interrupt: Predicate<E>) => Semantic<E>) & (<E>(supplier: Supplier<E>, interrupt: BiPredicate<E, bigint>) => Semantic<E>);
14
18
  export declare let interval: Functional<number, Semantic<number>> & BiFunctional<number, number, Semantic<number>>;
15
19
  export declare let iterate: <E>(generator: Generator<E>) => Semantic<E>;
package/dist/factory.js CHANGED
@@ -1,4 +1,4 @@
1
- import { isBigInt, isFunction, isIterable, isNumber, isObject, isPromise } from "./guard";
1
+ import { isBigInt, isFunction, isIterable, isNumber, isObject, isPromise, isAsyncIterable } from "./guard";
2
2
  import { useCompare, useTraverse } from "./hook";
3
3
  import { Semantic } from "./semantic";
4
4
  import { invalidate, validate } from "./utility";
@@ -148,6 +148,7 @@ export let fill = (element, count) => {
148
148
  }
149
149
  throw new TypeError("Invalid arguments.");
150
150
  };
151
+ ;
151
152
  export let from = (iterable) => {
152
153
  if (isIterable(iterable)) {
153
154
  return new Semantic((accept, interrupt) => {
@@ -166,6 +167,23 @@ export let from = (iterable) => {
166
167
  }
167
168
  });
168
169
  }
170
+ else if (isAsyncIterable(iterable)) {
171
+ return new Semantic(async (accept, interrupt) => {
172
+ try {
173
+ let index = 0n;
174
+ for await (let element of iterable) {
175
+ if (interrupt(element, index)) {
176
+ break;
177
+ }
178
+ accept(element, index);
179
+ index++;
180
+ }
181
+ }
182
+ catch (error) {
183
+ throw new Error("Uncaught error as creating from semantic.");
184
+ }
185
+ });
186
+ }
169
187
  throw new TypeError("Invalid arguments");
170
188
  };
171
189
  export let generate = (supplier, interrupt) => {
package/dist/guard.d.ts CHANGED
@@ -1,27 +1,36 @@
1
1
  import type { Collectable, OrderedCollectable, UnorderedCollectable } from "./collectable";
2
2
  import type { Collector } from "./collector";
3
+ import type { Hashable } from "./hash";
4
+ import type { HashMap, SemanticMap } from "./map";
3
5
  import type { Semantic } from "./semantic";
6
+ import type { HashSet } from "./set";
4
7
  import type { Statistics } from "./statistics";
5
8
  import type { AsyncFunction, MaybePrimitive, Primitive } from "./utility";
6
- export declare let isBoolean: (t: unknown) => t is boolean;
7
- export declare let isString: (t: unknown) => t is string;
8
- export declare let isNumber: (t: unknown) => t is number;
9
- export declare let isFunction: (t: unknown) => t is Function;
10
- export declare let isObject: (t: unknown) => t is object;
11
- export declare let isSymbol: (t: unknown) => t is symbol;
12
- export declare let isBigInt: (t: unknown) => t is bigint;
13
- export declare let isPrimitive: (t: MaybePrimitive<unknown>) => t is Primitive;
14
- export declare let isIterable: (t: unknown) => t is Iterable<unknown>;
15
- export declare let isSemantic: (t: unknown) => t is Semantic<unknown>;
16
- export declare let isCollector: (t: unknown) => t is Collector<unknown, unknown, unknown>;
17
- export declare let isCollectable: (t: unknown) => t is Collectable<unknown>;
18
- export declare let isOrderedCollectable: (t: unknown) => t is OrderedCollectable<unknown>;
19
- export declare let isWindowCollectable: (t: unknown) => t is OrderedCollectable<unknown>;
20
- export declare let isUnorderedCollectable: (t: unknown) => t is UnorderedCollectable<unknown>;
21
- export declare let isStatistics: (t: unknown) => t is Statistics<unknown, number | bigint>;
22
- export declare let isNumericStatistics: (t: unknown) => t is Statistics<unknown, number | bigint>;
23
- export declare let isBigIntStatistics: (t: unknown) => t is Statistics<unknown, number | bigint>;
24
- export declare let isPromise: (t: unknown) => t is Promise<unknown>;
25
- export declare let isAsyncFunction: (t: unknown) => t is AsyncFunction;
26
- export declare let isGeneratorFunction: (t: unknown) => t is Generator<unknown, unknown, unknown>;
27
- export declare let isAsyncGeneratorFunction: (t: unknown) => t is AsyncGenerator<unknown, unknown, unknown>;
9
+ import type { WindowCollectable } from "./window";
10
+ export declare let isBoolean: (target: unknown) => target is boolean;
11
+ export declare let isString: (target: unknown) => target is string;
12
+ export declare let isNumber: (target: unknown) => target is number;
13
+ export declare let isFunction: (target: unknown) => target is Function;
14
+ export declare let isObject: (target: unknown) => target is object;
15
+ export declare let isSymbol: (target: unknown) => target is symbol;
16
+ export declare let isBigInt: (target: unknown) => target is bigint;
17
+ export declare let isPrimitive: (target: MaybePrimitive<unknown>) => target is Primitive;
18
+ export declare let isAsyncIterable: (target: unknown) => target is Iterable<unknown>;
19
+ export declare let isIterable: (target: unknown) => target is Iterable<unknown>;
20
+ export declare let isSemantic: (target: unknown) => target is Semantic<unknown>;
21
+ export declare let isCollector: (target: unknown) => target is Collector<unknown, unknown, unknown>;
22
+ export declare let isCollectable: (target: unknown) => target is Collectable<unknown>;
23
+ export declare let isOrderedCollectable: (target: unknown) => target is OrderedCollectable<unknown>;
24
+ export declare let isWindowCollectable: (target: unknown) => target is WindowCollectable<unknown>;
25
+ export declare let isUnorderedCollectable: (target: unknown) => target is UnorderedCollectable<unknown>;
26
+ export declare let isStatistics: (target: unknown) => target is Statistics<unknown, number | bigint>;
27
+ export declare let isNumericStatistics: (target: unknown) => target is Statistics<unknown, number | bigint>;
28
+ export declare let isBigIntStatistics: (target: unknown) => target is Statistics<unknown, number | bigint>;
29
+ export declare let isSemanticMap: (target: unknown) => target is SemanticMap<unknown, unknown>;
30
+ export declare let isHashable: (target: unknown) => target is Hashable;
31
+ export declare let isHashMap: (target: unknown) => target is HashMap<unknown, unknown>;
32
+ export declare let isHashSet: (target: unknown) => target is HashSet<unknown>;
33
+ export declare let isPromise: (target: unknown) => target is Promise<unknown>;
34
+ export declare let isAsyncFunction: (target: unknown) => target is AsyncFunction;
35
+ export declare let isGeneratorFunction: (target: unknown) => target is Generator<unknown, unknown, unknown>;
36
+ export declare let isAsyncGeneratorFunction: (target: unknown) => target is AsyncGenerator<unknown, unknown, unknown>;
package/dist/guard.js CHANGED
@@ -1,109 +1,139 @@
1
- import { BigIntStatisticsSymbol, CollectableSymbol, CollectorsSymbol, NumericStatisticsSymbol, OrderedCollectableSymbol, SemanticSymbol, StatisticsSymbol, UnorderedCollectableSymbol } from "./symbol";
2
- export let isBoolean = (t) => {
3
- return typeof t === "boolean";
1
+ import { BigIntStatisticsSymbol, CollectableSymbol, CollectorsSymbol, HashableSymbol, NumericStatisticsSymbol, OrderedCollectableSymbol, SemanticMapSymbol, SemanticSymbol, StatisticsSymbol, UnorderedCollectableSymbol, WindowCollectableSymbol } from "./symbol";
2
+ export let isBoolean = (target) => {
3
+ return typeof target === "boolean";
4
4
  };
5
- export let isString = (t) => {
6
- return typeof t === "string";
5
+ export let isString = (target) => {
6
+ return typeof target === "string";
7
7
  };
8
- export let isNumber = (t) => {
9
- return typeof t === "number" && !Number.isNaN(t) && Number.isFinite(t);
8
+ export let isNumber = (target) => {
9
+ return typeof target === "number" && !Number.isNaN(target) && Number.isFinite(target);
10
10
  };
11
- export let isFunction = (t) => {
12
- return typeof t === "function";
11
+ export let isFunction = (target) => {
12
+ return typeof target === "function";
13
13
  };
14
- export let isObject = (t) => {
15
- return typeof t === "object" && t !== null;
14
+ export let isObject = (target) => {
15
+ return typeof target === "object" && target !== null;
16
16
  };
17
- export let isSymbol = (t) => {
18
- return typeof t === "symbol";
17
+ export let isSymbol = (target) => {
18
+ return typeof target === "symbol";
19
19
  };
20
- export let isBigInt = (t) => {
21
- return typeof t === "bigint";
20
+ export let isBigInt = (target) => {
21
+ return typeof target === "bigint";
22
22
  };
23
- export let isPrimitive = (t) => {
24
- return isBoolean(t) || isString(t) || isNumber(t) || isSymbol(t) || isBigInt(t) || isFunction(t);
23
+ export let isPrimitive = (target) => {
24
+ return isBoolean(target) || isString(target) || isNumber(target) || isSymbol(target) || isBigInt(target) || isFunction(target);
25
25
  };
26
- export let isIterable = (t) => {
27
- if (isObject(t)) {
28
- return isFunction(Reflect.get(t, Symbol.iterator));
26
+ export let isAsyncIterable = (target) => {
27
+ if (isObject(target)) {
28
+ return isFunction(Reflect.get(target, Symbol.asyncIterator));
29
29
  }
30
30
  return false;
31
31
  };
32
- export let isSemantic = (t) => {
33
- if (isObject(t)) {
34
- return Reflect.get(t, "Semantic") === SemanticSymbol;
32
+ export let isIterable = (target) => {
33
+ if (isObject(target)) {
34
+ return isFunction(Reflect.get(target, Symbol.iterator));
35
35
  }
36
36
  return false;
37
37
  };
38
- export let isCollector = (t) => {
39
- if (isObject(t)) {
40
- return Reflect.get(t, "Collector") === CollectorsSymbol;
38
+ export let isSemantic = (target) => {
39
+ if (isObject(target)) {
40
+ return Reflect.get(target, "Semantic") === SemanticSymbol;
41
41
  }
42
42
  return false;
43
43
  };
44
- export let isCollectable = (t) => {
45
- if (isObject(t)) {
46
- return Reflect.get(t, "Collectable") === CollectableSymbol;
44
+ export let isCollector = (target) => {
45
+ if (isObject(target)) {
46
+ return Reflect.get(target, "Collector") === CollectorsSymbol;
47
47
  }
48
48
  return false;
49
49
  };
50
- export let isOrderedCollectable = (t) => {
51
- if (isObject(t)) {
52
- return Reflect.get(t, "OrderedCollectable") === OrderedCollectableSymbol;
50
+ export let isCollectable = (target) => {
51
+ if (isObject(target)) {
52
+ return Reflect.get(target, "Collectable") === CollectableSymbol;
53
53
  }
54
54
  return false;
55
55
  };
56
- export let isWindowCollectable = (t) => {
57
- if (isObject(t)) {
58
- return Reflect.get(t, "WindowCollectable") === OrderedCollectableSymbol;
56
+ export let isOrderedCollectable = (target) => {
57
+ if (isObject(target)) {
58
+ return Reflect.get(target, "OrderedCollectable") === OrderedCollectableSymbol;
59
59
  }
60
60
  return false;
61
61
  };
62
- export let isUnorderedCollectable = (t) => {
63
- if (isObject(t)) {
64
- return Reflect.get(t, "UnorderedCollectable") === UnorderedCollectableSymbol;
62
+ export let isWindowCollectable = (target) => {
63
+ if (isObject(target)) {
64
+ return Reflect.get(target, "WindowCollectable") === WindowCollectableSymbol;
65
65
  }
66
66
  return false;
67
67
  };
68
- export let isStatistics = (t) => {
69
- if (isObject(t)) {
70
- return Reflect.get(t, "Statistics") === StatisticsSymbol;
68
+ export let isUnorderedCollectable = (target) => {
69
+ if (isObject(target)) {
70
+ return Reflect.get(target, "UnorderedCollectable") === UnorderedCollectableSymbol;
71
71
  }
72
72
  return false;
73
73
  };
74
- export let isNumericStatistics = (t) => {
75
- if (isObject(t)) {
76
- return Reflect.get(t, "NumericStatistics") === NumericStatisticsSymbol;
74
+ export let isStatistics = (target) => {
75
+ if (isObject(target)) {
76
+ return Reflect.get(target, "Statistics") === StatisticsSymbol;
77
77
  }
78
78
  return false;
79
79
  };
80
- export let isBigIntStatistics = (t) => {
81
- if (isObject(t)) {
82
- return Reflect.get(t, "BigIntStatistics") === BigIntStatisticsSymbol;
80
+ export let isNumericStatistics = (target) => {
81
+ if (isObject(target)) {
82
+ return Reflect.get(target, "NumericStatistics") === NumericStatisticsSymbol;
83
83
  }
84
84
  return false;
85
85
  };
86
- export let isPromise = (t) => {
87
- if (isObject(t)) {
88
- return isFunction(Reflect.get(t, "then")) && isFunction(Reflect.get(t, "catch"));
86
+ export let isBigIntStatistics = (target) => {
87
+ if (isObject(target)) {
88
+ return Reflect.get(target, "BigIntStatistics") === BigIntStatisticsSymbol;
89
89
  }
90
90
  return false;
91
91
  };
92
- export let isAsyncFunction = (t) => {
93
- if (isFunction(t)) {
94
- return Reflect.get(t, Symbol.toStringTag) === "AsyncFunction" && t.constructor.name === "AsyncFunction";
92
+ export let isSemanticMap = (target) => {
93
+ if (isObject(target)) {
94
+ return Reflect.get(target, "SemanticMap") === SemanticMapSymbol;
95
95
  }
96
96
  return false;
97
97
  };
98
- export let isGeneratorFunction = (t) => {
99
- if (isObject(t)) {
100
- return isFunction(t) && Reflect.get(t, "constructor").name === "GeneratorFunction";
98
+ export let isHashable = (target) => {
99
+ if (isObject(target)) {
100
+ return Reflect.get(target, HashableSymbol) === HashableSymbol;
101
101
  }
102
102
  return false;
103
103
  };
104
- export let isAsyncGeneratorFunction = (t) => {
105
- if (isObject(t)) {
106
- return isFunction(t) && Reflect.get(t, "constructor").name === "AsyncGeneratorFunction";
104
+ export let isHashMap = (target) => {
105
+ if (isObject(target)) {
106
+ return Reflect.get(target, "HashMap") === SemanticMapSymbol;
107
+ }
108
+ return false;
109
+ };
110
+ export let isHashSet = (target) => {
111
+ if (isObject(target)) {
112
+ return false;
113
+ }
114
+ return false;
115
+ };
116
+ export let isPromise = (target) => {
117
+ if (isObject(target)) {
118
+ return isFunction(Reflect.get(target, "then")) && isFunction(Reflect.get(target, "catch"));
119
+ }
120
+ return false;
121
+ };
122
+ export let isAsyncFunction = (target) => {
123
+ if (isFunction(target)) {
124
+ return Reflect.get(target, Symbol.toStringTag) === "AsyncFunction" && target.constructor.name === "AsyncFunction";
125
+ }
126
+ return false;
127
+ };
128
+ export let isGeneratorFunction = (target) => {
129
+ if (isObject(target)) {
130
+ return isFunction(target) && Reflect.get(target, "constructor").name === "GeneratorFunction";
131
+ }
132
+ return false;
133
+ };
134
+ export let isAsyncGeneratorFunction = (target) => {
135
+ if (isObject(target)) {
136
+ return isFunction(target) && Reflect.get(target, "constructor").name === "AsyncGeneratorFunction";
107
137
  }
108
138
  return false;
109
139
  };
package/dist/hash.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ import { type Type } from "./utility";
2
+ export interface Hashable {
3
+ }
4
+ export declare let maskOf: (type: Type) => bigint;
5
+ interface Handler<T> {
6
+ (value: T): bigint;
7
+ }
8
+ export declare let register: <T>(type: Type, handler: Handler<T>) => void;
9
+ export declare let unregister: (type: Type) => void;
10
+ interface UseHash {
11
+ <T = unknown>(target: T): bigint;
12
+ }
13
+ export declare let useHash: UseHash;
14
+ export {};