@e280/stz 0.3.0-next.0 → 0.3.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.
package/README.md CHANGED
@@ -9,6 +9,38 @@
9
9
 
10
10
  ## 🥨 stz primitives
11
11
 
12
+ ### 🍏 utensil fns
13
+ > everyday helper fns
14
+
15
+ - **got(value)** — throw an error if the value is null or undefined
16
+ ```ts
17
+ const value = got(nullableValue)
18
+ ```
19
+
20
+ #### map helpers
21
+ - **need(map, key)** — return-or-throw a map value
22
+ ```ts
23
+ const value = need(map, "my_key")
24
+ ```
25
+ - **guarantee(map, key, makeFn)** — get-or-create a map value
26
+ ```ts
27
+ const value = guarantee(map, "my_key", () => 123)
28
+ ```
29
+ - **inserts(map, entries)** — set many entries at once
30
+ ```ts
31
+ inserts(map, [["my_key1", 123], ["my_key2", 234]])
32
+ ```
33
+
34
+ #### set helpers
35
+ - **adds(set, values)** — add many values at once
36
+ ```ts
37
+ adds(set, ["alpha", "bravo", "charlie"])
38
+ ```
39
+ - **deletes(set, values)** — delete many values at once
40
+ ```ts
41
+ deletes(map, ["alpha", "bravo", "charlie"])
42
+ ```
43
+
12
44
  ### 🍏 `pub` and `sub`
13
45
  > ergonomic event emitters
14
46
 
@@ -130,7 +162,7 @@ await all(
130
162
  ```ts
131
163
  import {concurrent} from "@e280/stz"
132
164
 
133
- cons {slept, hello, whatever} = await concurrent({
165
+ const {slept, hello, whatever} = await concurrent({
134
166
  slept: nap(500),
135
167
  hello: Promise.resolve("hello"),
136
168
  whatever: fetch("whatever.json"),
@@ -172,43 +204,6 @@ import {disposer} from "@e280/stz"
172
204
  dispose()
173
205
  ```
174
206
 
175
- ### 🍏 G Crew
176
- > extended js data types
177
-
178
- #### GMap
179
- > extended js Map
180
- - many are saying it's *"The Deluxe Mapping Experience"*
181
- ```ts
182
- import {GMap} from "@e280/stz"
183
-
184
- const map = new GMap<number, string>([
185
- [1, "hello"],
186
- [2, "world"],
187
- ])
188
- ```
189
- - `map.need(key)` — returns the value for key.. if missing, throw an error
190
- ```ts
191
- const value = map.need(1)
192
- // "hello"
193
- ```
194
- - `map.guarantee(key, makeFn)` — returns the value for `key`.. if missing, run `makeFn` to set and return the value
195
- ```ts
196
- const value = map.guarantee(3, () => "rofl")
197
- // "rofl"
198
- ```
199
-
200
- #### GSet
201
- > extended js Set
202
- - `new GSet<T>()`
203
- - `set.adds(item1, item2, item3)` — add multiple items without a for-loop
204
- - `set.deletes(item1, item2, item3)` — add multiple items without a for-loop
205
-
206
- #### GWeakMap
207
- > extended js WeakMap
208
- - `new GWeakMap<K, V>()`
209
- - `weakMap.need(key)` — returns value for key.. if missing, throw an error
210
- - `weakMap.guarantee(key, makeFn)` — returns the value for key.. if missing, run `makeFn` to set and return the value
211
-
212
207
 
213
208
 
214
209
  <br/>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e280/stz",
3
- "version": "0.3.0-next.0",
3
+ "version": "0.3.0",
4
4
  "description": "everyday ts fns for everything",
5
5
  "license": "MIT",
6
6
  "author": "Chase Moskal <chasemoskal@gmail.com>",
@@ -23,7 +23,7 @@
23
23
  },
24
24
  "devDependencies": {
25
25
  "@e280/science": "^0.1.11",
26
- "@types/node": "^25.7.0",
26
+ "@types/node": "^25.9.3",
27
27
  "typescript": "^6.0.3"
28
28
  },
29
29
  "keywords": [
package/s/index.ts CHANGED
@@ -14,6 +14,7 @@ export * from "./deep/index.js"
14
14
  export * from "./dig/dig.js"
15
15
 
16
16
  export * from "./queue/queue.js"
17
+ export * from "./rand/index.js"
17
18
 
18
19
  export * from "./ok/index.js"
19
20
  export * from "./toq/index.js"
@@ -0,0 +1,6 @@
1
+
2
+ export * from "./rand.js"
3
+ export * from "./seed.js"
4
+ export * from "./types.js"
5
+ export * from "./u32ify.js"
6
+
package/s/rand/rand.ts ADDED
@@ -0,0 +1,78 @@
1
+
2
+ import {Random} from "./types.js"
3
+ import {u32ify} from "./u32ify.js"
4
+
5
+ /** facility for doing common random things, like picking a random item from an array. */
6
+ export class Rand {
7
+ constructor(public random: Random = Math.random) {}
8
+
9
+ /** random positive unsigned 32-bit integer. */
10
+ u32() {
11
+ return u32ify(this.random())
12
+ }
13
+
14
+ /** randomly returns true given a probability fraction. */
15
+ roll(chance = 0.5) {
16
+ return this.random() < chance
17
+ }
18
+
19
+ /** random number between two numbers. */
20
+ range(min: number, max: number) {
21
+ return min + (this.random() * (max - min))
22
+ }
23
+
24
+ /** random integer from min to max (inclusive). */
25
+ integerRange(min: number, max: number) {
26
+ return min + Math.floor(this.random() * (max - min + 1))
27
+ }
28
+
29
+ /** random array index given an array length. */
30
+ index(length: number) {
31
+ return Math.floor(this.random() * length)
32
+ }
33
+
34
+ /** randomly choose one item from the provided array. */
35
+ pick<T>(array: T[]) {
36
+ return array[this.index(array.length)]
37
+ }
38
+
39
+ /** randomly select a given number of array items. */
40
+ select<T>(count: number, array: T[]) {
41
+ const copy = [...array]
42
+ if (count >= array.length)
43
+ return copy
44
+
45
+ const selection: T[] = []
46
+ for (let i = 0; i < count; i++)
47
+ selection.push(this.yoink(copy))
48
+ return selection
49
+ }
50
+
51
+ /** remove a random item from the array, and return it. */
52
+ yoink<T>(array: T[]) {
53
+ const index = this.index(array.length)
54
+ const [item] = array.splice(index, 1)
55
+ return item
56
+ }
57
+
58
+ /** randomly remove the given number of items from the array. */
59
+ extract<T>(count: number, array: T[]) {
60
+ const selection: T[] = []
61
+ for (let i = 0; i < count; i++) {
62
+ if (array.length === 0)
63
+ return selection
64
+ selection.push(this.yoink(array))
65
+ }
66
+ return selection
67
+ }
68
+
69
+ /** randomly shuffle an array in-place using fisher-yates. */
70
+ shuffle<T>(array: T[]) {
71
+ for (let i = array.length - 1; i > 0; i--) {
72
+ const j = Math.floor(this.random() * (i + 1))
73
+ ;[array[i], array[j]] = [array[j], array[i]]
74
+ }
75
+ return array
76
+ }
77
+ }
78
+
package/s/rand/seed.ts ADDED
@@ -0,0 +1,20 @@
1
+
2
+ import {Random} from "./types.js"
3
+ import {u32ify} from "./u32ify.js"
4
+
5
+ const m = 2147483647
6
+ const a = 48271
7
+
8
+ export function seed(u32 = u32ify(Math.random())): Random {
9
+ u32 = (u32 ^ 0x6D2B79F5) + 0x1E35A7BD
10
+ u32 = ((u32 >>> 0) % m) || 1
11
+
12
+ function random() {
13
+ u32 = (a * u32) % m
14
+ return u32 / m
15
+ }
16
+
17
+ random()
18
+ return random
19
+ }
20
+
@@ -0,0 +1,4 @@
1
+
2
+ /** fn that returns random number fraction between 0 and 1. */
3
+ export type Random = () => number
4
+
@@ -0,0 +1,6 @@
1
+
2
+ /** convert a fraction number (between 0 and 1) into an unsigned 32-bit integer. */
3
+ export function u32ify(fraction: number) {
4
+ return Math.floor(fraction * 0x100000000)
5
+ }
6
+
package/s/utensils/map.ts CHANGED
@@ -5,7 +5,7 @@ type MapLike<K, V> = {
5
5
  set(key: K, value: V): unknown
6
6
  }
7
7
 
8
- export function need<K, V>(map: MapLike<K, V>, key: K) {
8
+ export function need<K, V>(map: Pick<MapLike<K, V>, "has" | "get">, key: K) {
9
9
  if (map.has(key))
10
10
  return map.get(key) as V
11
11
  else
@@ -22,7 +22,7 @@ export function guarantee<K, V>(map: MapLike<K, V>, key: K, make: () => V) {
22
22
  }
23
23
  }
24
24
 
25
- export function inserts<K, V, M extends MapLike<K, V>>(map: M, entries: Iterable<[K, V]>) {
25
+ export function inserts<K, V, M extends Pick<MapLike<K, V>, "set">>(map: M, entries: Iterable<[K, V]>) {
26
26
  for (const [key, value] of entries)
27
27
  map.set(key, value)
28
28
  return map
package/s/utensils/set.ts CHANGED
@@ -1,17 +1,11 @@
1
1
 
2
- type SetLike<V> = {
3
- has(value: V): boolean
4
- add(value: V): void
5
- delete(value: V): void
6
- }
7
-
8
- export function adds<V, S extends SetLike<V>>(set: S, values: Iterable<V>) {
2
+ export function adds<V, S extends {add(value: V): void}>(set: S, values: Iterable<V>) {
9
3
  for (const value of values)
10
4
  set.add(value)
11
5
  return set
12
6
  }
13
7
 
14
- export function deletes<V, S extends SetLike<V>>(set: S, values: Iterable<V>) {
8
+ export function deletes<V, S extends {delete(value: V): void}>(set: S, values: Iterable<V>) {
15
9
  for (const value of values)
16
10
  set.delete(value)
17
11
  return set
package/x/index.d.ts CHANGED
@@ -10,6 +10,7 @@ export * from "./debounce/types.js";
10
10
  export * from "./deep/index.js";
11
11
  export * from "./dig/dig.js";
12
12
  export * from "./queue/queue.js";
13
+ export * from "./rand/index.js";
13
14
  export * from "./ok/index.js";
14
15
  export * from "./toq/index.js";
15
16
  export * from "./maybe/index.js";
package/x/index.js CHANGED
@@ -10,6 +10,7 @@ export * from "./debounce/types.js";
10
10
  export * from "./deep/index.js";
11
11
  export * from "./dig/dig.js";
12
12
  export * from "./queue/queue.js";
13
+ export * from "./rand/index.js";
13
14
  export * from "./ok/index.js";
14
15
  export * from "./toq/index.js";
15
16
  export * from "./maybe/index.js";
package/x/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../s/index.ts"],"names":[],"mappings":"AACA,cAAc,6BAA6B,CAAA;AAC3C,cAAc,+BAA+B,CAAA;AAC7C,cAAc,yBAAyB,CAAA;AACvC,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,eAAe,CAAA;AAE7B,cAAc,wBAAwB,CAAA;AACtC,cAAc,2BAA2B,CAAA;AACzC,cAAc,qBAAqB,CAAA;AAEnC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,cAAc,CAAA;AAE5B,cAAc,kBAAkB,CAAA;AAEhC,cAAc,eAAe,CAAA;AAC7B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,kBAAkB,CAAA;AAEhC,cAAc,mBAAmB,CAAA;AACjC,cAAc,mBAAmB,CAAA;AACjC,cAAc,mBAAmB,CAAA;AAEjC,cAAc,UAAU,CAAA;AACxB,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,cA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,mBAAmB,CAAA;AACjC,cAAc,mBAAmB,CAAA;AACjC,cAAc,mBAAmB,CAAA;AAEjC,cAAc,UAAU,CAAA;AACxB,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,cAAc,cAAc,CAAA;AAC5B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kBAAkB,CAAA;AAChC,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,qBAAqB,CAAA;AACnC,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,eAAe,CAAA;AAC7B,cAAc,mBAAmB,CAAA;AACjC,cAAc,mBAAmB,CAAA;AACjC,cAAc,SAAS,CAAA;AACvB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AACzB,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA"}
@@ -0,0 +1,4 @@
1
+ export * from "./rand.js";
2
+ export * from "./seed.js";
3
+ export * from "./types.js";
4
+ export * from "./u32ify.js";
@@ -0,0 +1,5 @@
1
+ export * from "./rand.js";
2
+ export * from "./seed.js";
3
+ export * from "./types.js";
4
+ export * from "./u32ify.js";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../s/rand/index.ts"],"names":[],"mappings":"AACA,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA"}
@@ -0,0 +1,26 @@
1
+ import { Random } from "./types.js";
2
+ /** facility for doing common random things, like picking a random item from an array. */
3
+ export declare class Rand {
4
+ random: Random;
5
+ constructor(random?: Random);
6
+ /** random positive unsigned 32-bit integer. */
7
+ u32(): number;
8
+ /** randomly returns true given a probability fraction. */
9
+ roll(chance?: number): boolean;
10
+ /** random number between two numbers. */
11
+ range(min: number, max: number): number;
12
+ /** random integer from min to max (inclusive). */
13
+ integerRange(min: number, max: number): number;
14
+ /** random array index given an array length. */
15
+ index(length: number): number;
16
+ /** randomly choose one item from the provided array. */
17
+ pick<T>(array: T[]): T;
18
+ /** randomly select a given number of array items. */
19
+ select<T>(count: number, array: T[]): T[];
20
+ /** remove a random item from the array, and return it. */
21
+ yoink<T>(array: T[]): T;
22
+ /** randomly remove the given number of items from the array. */
23
+ extract<T>(count: number, array: T[]): T[];
24
+ /** randomly shuffle an array in-place using fisher-yates. */
25
+ shuffle<T>(array: T[]): T[];
26
+ }
package/x/rand/rand.js ADDED
@@ -0,0 +1,67 @@
1
+ import { u32ify } from "./u32ify.js";
2
+ /** facility for doing common random things, like picking a random item from an array. */
3
+ export class Rand {
4
+ random;
5
+ constructor(random = Math.random) {
6
+ this.random = random;
7
+ }
8
+ /** random positive unsigned 32-bit integer. */
9
+ u32() {
10
+ return u32ify(this.random());
11
+ }
12
+ /** randomly returns true given a probability fraction. */
13
+ roll(chance = 0.5) {
14
+ return this.random() < chance;
15
+ }
16
+ /** random number between two numbers. */
17
+ range(min, max) {
18
+ return min + (this.random() * (max - min));
19
+ }
20
+ /** random integer from min to max (inclusive). */
21
+ integerRange(min, max) {
22
+ return min + Math.floor(this.random() * (max - min + 1));
23
+ }
24
+ /** random array index given an array length. */
25
+ index(length) {
26
+ return Math.floor(this.random() * length);
27
+ }
28
+ /** randomly choose one item from the provided array. */
29
+ pick(array) {
30
+ return array[this.index(array.length)];
31
+ }
32
+ /** randomly select a given number of array items. */
33
+ select(count, array) {
34
+ const copy = [...array];
35
+ if (count >= array.length)
36
+ return copy;
37
+ const selection = [];
38
+ for (let i = 0; i < count; i++)
39
+ selection.push(this.yoink(copy));
40
+ return selection;
41
+ }
42
+ /** remove a random item from the array, and return it. */
43
+ yoink(array) {
44
+ const index = this.index(array.length);
45
+ const [item] = array.splice(index, 1);
46
+ return item;
47
+ }
48
+ /** randomly remove the given number of items from the array. */
49
+ extract(count, array) {
50
+ const selection = [];
51
+ for (let i = 0; i < count; i++) {
52
+ if (array.length === 0)
53
+ return selection;
54
+ selection.push(this.yoink(array));
55
+ }
56
+ return selection;
57
+ }
58
+ /** randomly shuffle an array in-place using fisher-yates. */
59
+ shuffle(array) {
60
+ for (let i = array.length - 1; i > 0; i--) {
61
+ const j = Math.floor(this.random() * (i + 1));
62
+ [array[i], array[j]] = [array[j], array[i]];
63
+ }
64
+ return array;
65
+ }
66
+ }
67
+ //# sourceMappingURL=rand.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rand.js","sourceRoot":"","sources":["../../s/rand/rand.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,MAAM,EAAC,MAAM,aAAa,CAAA;AAElC,yFAAyF;AACzF,MAAM,OAAO,IAAI;IACG;IAAnB,YAAmB,SAAiB,IAAI,CAAC,MAAM;QAA5B,WAAM,GAAN,MAAM,CAAsB;IAAG,CAAC;IAEnD,+CAA+C;IAC/C,GAAG;QACF,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAA;IAC7B,CAAC;IAED,0DAA0D;IAC1D,IAAI,CAAC,MAAM,GAAG,GAAG;QAChB,OAAO,IAAI,CAAC,MAAM,EAAE,GAAG,MAAM,CAAA;IAC9B,CAAC;IAED,yCAAyC;IACzC,KAAK,CAAC,GAAW,EAAE,GAAW;QAC7B,OAAO,GAAG,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC,CAAA;IA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G,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC;YAChC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;gBACrB,OAAO,SAAS,CAAA;YACjB,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAA;QAClC,CAAC;QACD,OAAO,SAAS,CAAA;IACjB,CAAC;IAED,6DAA6D;IAC7D,OAAO,CAAI,KAAU;QACpB,KAAK,IAAI,CAAC,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;YAC3C,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAC5C;YAAA,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;QAC7C,CAAC;QACD,OAAO,KAAK,CAAA;IACb,CAAC;CACD"}
@@ -0,0 +1,2 @@
1
+ import { Random } from "./types.js";
2
+ export declare function seed(u32?: number): Random;
package/x/rand/seed.js ADDED
@@ -0,0 +1,14 @@
1
+ import { u32ify } from "./u32ify.js";
2
+ const m = 2147483647;
3
+ const a = 48271;
4
+ export function seed(u32 = u32ify(Math.random())) {
5
+ u32 = (u32 ^ 0x6D2B79F5) + 0x1E35A7BD;
6
+ u32 = ((u32 >>> 0) % m) || 1;
7
+ function random() {
8
+ u32 = (a * u32) % m;
9
+ return u32 / m;
10
+ }
11
+ random();
12
+ return random;
13
+ }
14
+ //# sourceMappingURL=seed.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"seed.js","sourceRoot":"","sources":["../../s/rand/seed.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,MAAM,EAAC,MAAM,aAAa,CAAA;AAElC,MAAM,CAAC,GAAG,UAAU,CAAA;AACpB,MAAM,CAAC,GAAG,KAAK,CAAA;AAEf,MAAM,UAAU,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;IAC/C,GAAG,GAAG,CAAC,GAAG,GAAG,UAAU,CAAC,GAAG,UAAU,CAAA;IACrC,GAAG,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAA;IAE5B,SAAS,MAAM;QACd,GAAG,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,CAAA;QACnB,OAAO,GAAG,GAAG,CAAC,CAAA;IACf,CAAC;IAED,MAAM,EAAE,CAAA;IACR,OAAO,MAAM,CAAA;AACd,CAAC"}
@@ -0,0 +1,2 @@
1
+ /** fn that returns random number fraction between 0 and 1. */
2
+ export type Random = () => number;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../s/rand/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ /** convert a fraction number (between 0 and 1) into an unsigned 32-bit integer. */
2
+ export declare function u32ify(fraction: number): number;
@@ -0,0 +1,5 @@
1
+ /** convert a fraction number (between 0 and 1) into an unsigned 32-bit integer. */
2
+ export function u32ify(fraction) {
3
+ return Math.floor(fraction * 0x100000000);
4
+ }
5
+ //# sourceMappingURL=u32ify.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"u32ify.js","sourceRoot":"","sources":["../../s/rand/u32ify.ts"],"names":[],"mappings":"AACA,mFAAmF;AACnF,MAAM,UAAU,MAAM,CAAC,QAAgB;IACtC,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,WAAW,CAAC,CAAA;AAC1C,CAAC"}
@@ -3,7 +3,7 @@ type MapLike<K, V> = {
3
3
  get(key: K): V | undefined;
4
4
  set(key: K, value: V): unknown;
5
5
  };
6
- export declare function need<K, V>(map: MapLike<K, V>, key: K): V;
6
+ export declare function need<K, V>(map: Pick<MapLike<K, V>, "has" | "get">, key: K): V;
7
7
  export declare function guarantee<K, V>(map: MapLike<K, V>, key: K, make: () => V): V;
8
- export declare function inserts<K, V, M extends MapLike<K, V>>(map: M, entries: Iterable<[K, V]>): M;
8
+ export declare function inserts<K, V, M extends Pick<MapLike<K, V>, "set">>(map: M, entries: Iterable<[K, V]>): M;
9
9
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"map.js","sourceRoot":"","sources":["../../s/utensils/map.ts"],"names":[],"mappings":"AAOA,MAAM,UAAU,IAAI,CAAO,GAAkB,EAAE,GAAM;IACpD,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC;QACf,OAAO,GAAG,CAAC,GAAG,CAAC,GAAG,CAAM,CAAA;;QAExB,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAA;AACzC,CAAC;AAED,MAAM,UAAU,SAAS,CAAO,GAAkB,EAAE,GAAM,EAAE,IAAa;IACxE,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC;QACf,OAAO,GAAG,CAAC,GAAG,CAAC,GAAG,CAAE,CAAA;SAChB,CAAC;QACL,MAAM,KAAK,GAAG,IAAI,EAAE,CAAA;QACpB,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;QACnB,OAAO,KAAK,CAAA;IACb,CAAC;AACF,CAAC;AAED,MAAM,UAAU,OAAO,CAAgC,GAAM,EAAE,OAAyB;IACvF,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,OAAO;QACjC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;IACpB,OAAO,GAAG,CAAA;AACX,CAAC"}
1
+ {"version":3,"file":"map.js","sourceRoot":"","sources":["../../s/utensils/map.ts"],"names":[],"mappings":"AAOA,MAAM,UAAU,IAAI,CAAO,GAAuC,EAAE,GAAM;IACzE,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC;QACf,OAAO,GAAG,CAAC,GAAG,CAAC,GAAG,CAAM,CAAA;;QAExB,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAA;AACzC,CAAC;AAED,MAAM,UAAU,SAAS,CAAO,GAAkB,EAAE,GAAM,EAAE,IAAa;IACxE,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC;QACf,OAAO,GAAG,CAAC,GAAG,CAAC,GAAG,CAAE,CAAA;SAChB,CAAC;QACL,MAAM,KAAK,GAAG,IAAI,EAAE,CAAA;QACpB,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;QACnB,OAAO,KAAK,CAAA;IACb,CAAC;AACF,CAAC;AAED,MAAM,UAAU,OAAO,CAA6C,GAAM,EAAE,OAAyB;IACpG,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,OAAO;QACjC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;IACpB,OAAO,GAAG,CAAA;AACX,CAAC"}
@@ -1,8 +1,6 @@
1
- type SetLike<V> = {
2
- has(value: V): boolean;
1
+ export declare function adds<V, S extends {
3
2
  add(value: V): void;
3
+ }>(set: S, values: Iterable<V>): S;
4
+ export declare function deletes<V, S extends {
4
5
  delete(value: V): void;
5
- };
6
- export declare function adds<V, S extends SetLike<V>>(set: S, values: Iterable<V>): S;
7
- export declare function deletes<V, S extends SetLike<V>>(set: S, values: Iterable<V>): S;
8
- export {};
6
+ }>(set: S, values: Iterable<V>): S;
@@ -1 +1 @@
1
- {"version":3,"file":"set.js","sourceRoot":"","sources":["../../s/utensils/set.ts"],"names":[],"mappings":"AAOA,MAAM,UAAU,IAAI,CAA0B,GAAM,EAAE,MAAmB;IACxE,KAAK,MAAM,KAAK,IAAI,MAAM;QACzB,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;IACf,OAAO,GAAG,CAAA;AACX,CAAC;AAED,MAAM,UAAU,OAAO,CAA0B,GAAM,EAAE,MAAmB;IAC3E,KAAK,MAAM,KAAK,IAAI,MAAM;QACzB,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IAClB,OAAO,GAAG,CAAA;AACX,CAAC"}
1
+ {"version":3,"file":"set.js","sourceRoot":"","sources":["../../s/utensils/set.ts"],"names":[],"mappings":"AACA,MAAM,UAAU,IAAI,CAAqC,GAAM,EAAE,MAAmB;IACnF,KAAK,MAAM,KAAK,IAAI,MAAM;QACzB,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;IACf,OAAO,GAAG,CAAA;AACX,CAAC;AAED,MAAM,UAAU,OAAO,CAAwC,GAAM,EAAE,MAAmB;IACzF,KAAK,MAAM,KAAK,IAAI,MAAM;QACzB,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IAClB,OAAO,GAAG,CAAA;AACX,CAAC"}