effect 2.0.3 → 2.0.5

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 (112) hide show
  1. package/FiberMap/package.json +6 -0
  2. package/FiberSet/package.json +6 -0
  3. package/Trie/package.json +6 -0
  4. package/dist/cjs/FiberMap.js +190 -0
  5. package/dist/cjs/FiberMap.js.map +1 -0
  6. package/dist/cjs/FiberSet.js +150 -0
  7. package/dist/cjs/FiberSet.js.map +1 -0
  8. package/dist/cjs/MutableHashMap.js +11 -1
  9. package/dist/cjs/MutableHashMap.js.map +1 -1
  10. package/dist/cjs/MutableHashSet.js +7 -1
  11. package/dist/cjs/MutableHashSet.js.map +1 -1
  12. package/dist/cjs/MutableList.js +8 -11
  13. package/dist/cjs/MutableList.js.map +1 -1
  14. package/dist/cjs/Schedule.js.map +1 -1
  15. package/dist/cjs/Struct.js +16 -1
  16. package/dist/cjs/Struct.js.map +1 -1
  17. package/dist/cjs/Trie.js +680 -0
  18. package/dist/cjs/Trie.js.map +1 -0
  19. package/dist/cjs/index.js +8 -2
  20. package/dist/cjs/index.js.map +1 -1
  21. package/dist/cjs/internal/hashMap/node.js +2 -2
  22. package/dist/cjs/internal/hashMap/node.js.map +1 -1
  23. package/dist/cjs/internal/pubsub.js +11 -17
  24. package/dist/cjs/internal/pubsub.js.map +1 -1
  25. package/dist/cjs/internal/redBlackTree/node.js +35 -30
  26. package/dist/cjs/internal/redBlackTree/node.js.map +1 -1
  27. package/dist/cjs/internal/redBlackTree.js +69 -13
  28. package/dist/cjs/internal/redBlackTree.js.map +1 -1
  29. package/dist/cjs/internal/schedule.js +1 -1
  30. package/dist/cjs/internal/schedule.js.map +1 -1
  31. package/dist/cjs/internal/stack.js +6 -11
  32. package/dist/cjs/internal/stack.js.map +1 -1
  33. package/dist/cjs/internal/trie.js +588 -0
  34. package/dist/cjs/internal/trie.js.map +1 -0
  35. package/dist/cjs/internal/version.js +1 -1
  36. package/dist/dts/FiberMap.d.ts +135 -0
  37. package/dist/dts/FiberMap.d.ts.map +1 -0
  38. package/dist/dts/FiberSet.d.ts +99 -0
  39. package/dist/dts/FiberSet.d.ts.map +1 -0
  40. package/dist/dts/MutableHashMap.d.ts +4 -0
  41. package/dist/dts/MutableHashMap.d.ts.map +1 -1
  42. package/dist/dts/MutableHashSet.d.ts +5 -0
  43. package/dist/dts/MutableHashSet.d.ts.map +1 -1
  44. package/dist/dts/MutableList.d.ts.map +1 -1
  45. package/dist/dts/Schedule.d.ts +2 -1
  46. package/dist/dts/Schedule.d.ts.map +1 -1
  47. package/dist/dts/Struct.d.ts +17 -3
  48. package/dist/dts/Struct.d.ts.map +1 -1
  49. package/dist/dts/Trie.d.ts +740 -0
  50. package/dist/dts/Trie.d.ts.map +1 -0
  51. package/dist/dts/Types.d.ts +4 -0
  52. package/dist/dts/Types.d.ts.map +1 -1
  53. package/dist/dts/index.d.ts +26 -0
  54. package/dist/dts/index.d.ts.map +1 -1
  55. package/dist/dts/internal/redBlackTree/node.d.ts +8 -0
  56. package/dist/dts/internal/redBlackTree/node.d.ts.map +1 -1
  57. package/dist/dts/internal/stack.d.ts +1 -1
  58. package/dist/dts/internal/stack.d.ts.map +1 -1
  59. package/dist/dts/internal/trie.d.ts +2 -0
  60. package/dist/dts/internal/trie.d.ts.map +1 -0
  61. package/dist/dts/internal/version.d.ts +1 -1
  62. package/dist/esm/FiberMap.js +154 -0
  63. package/dist/esm/FiberMap.js.map +1 -0
  64. package/dist/esm/FiberSet.js +114 -0
  65. package/dist/esm/FiberSet.js.map +1 -0
  66. package/dist/esm/MutableHashMap.js +9 -0
  67. package/dist/esm/MutableHashMap.js.map +1 -1
  68. package/dist/esm/MutableHashSet.js +5 -0
  69. package/dist/esm/MutableHashSet.js.map +1 -1
  70. package/dist/esm/MutableList.js +8 -11
  71. package/dist/esm/MutableList.js.map +1 -1
  72. package/dist/esm/Schedule.js.map +1 -1
  73. package/dist/esm/Struct.js +14 -0
  74. package/dist/esm/Struct.js.map +1 -1
  75. package/dist/esm/Trie.js +648 -0
  76. package/dist/esm/Trie.js.map +1 -0
  77. package/dist/esm/index.js +26 -0
  78. package/dist/esm/index.js.map +1 -1
  79. package/dist/esm/internal/hashMap/node.js +2 -2
  80. package/dist/esm/internal/hashMap/node.js.map +1 -1
  81. package/dist/esm/internal/pubsub.js +11 -17
  82. package/dist/esm/internal/pubsub.js.map +1 -1
  83. package/dist/esm/internal/redBlackTree/node.js +31 -25
  84. package/dist/esm/internal/redBlackTree/node.js.map +1 -1
  85. package/dist/esm/internal/redBlackTree.js +69 -13
  86. package/dist/esm/internal/redBlackTree.js.map +1 -1
  87. package/dist/esm/internal/schedule.js +1 -1
  88. package/dist/esm/internal/schedule.js.map +1 -1
  89. package/dist/esm/internal/stack.js +4 -9
  90. package/dist/esm/internal/stack.js.map +1 -1
  91. package/dist/esm/internal/trie.js +547 -0
  92. package/dist/esm/internal/trie.js.map +1 -0
  93. package/dist/esm/internal/version.js +1 -1
  94. package/package.json +25 -1
  95. package/src/FiberMap.ts +296 -0
  96. package/src/FiberSet.ts +194 -0
  97. package/src/MutableHashMap.ts +10 -0
  98. package/src/MutableHashSet.ts +6 -0
  99. package/src/MutableList.ts +15 -7
  100. package/src/Schedule.ts +2 -1
  101. package/src/Struct.ts +24 -6
  102. package/src/Trie.ts +772 -0
  103. package/src/Types.ts +5 -0
  104. package/src/index.ts +29 -0
  105. package/src/internal/hashMap/node.ts +3 -3
  106. package/src/internal/pubsub.ts +15 -14
  107. package/src/internal/redBlackTree/node.ts +37 -17
  108. package/src/internal/redBlackTree.ts +73 -38
  109. package/src/internal/schedule.ts +2 -2
  110. package/src/internal/stack.ts +8 -2
  111. package/src/internal/trie.ts +721 -0
  112. package/src/internal/version.ts +1 -1
@@ -0,0 +1,740 @@
1
+ /**
2
+ * A `Trie` is used for locating specific `string` keys from within a set.
3
+ *
4
+ * It works similar to `HashMap`, but with keys required to be `string`.
5
+ * This constraint unlocks some performance optimizations and new methods to get string prefixes (e.g. `keysWithPrefix`, `longestPrefixOf`).
6
+ *
7
+ * Prefix search is also the main feature that makes a `Trie` more suited than `HashMap` for certain usecases.
8
+ *
9
+ * A `Trie` is often used to store a dictionary (list of words) that can be searched
10
+ * in a manner that allows for efficient generation of completion lists
11
+ * (e.g. predict the rest of a word a user is typing).
12
+ *
13
+ * A `Trie` has O(n) lookup time where `n` is the size of the key,
14
+ * or even less than `n` on search misses.
15
+ *
16
+ * @since 2.0.0
17
+ */
18
+ import type { Equal } from "./Equal.js";
19
+ import type { Inspectable } from "./Inspectable.js";
20
+ import type { Option } from "./Option.js";
21
+ import type { Pipeable } from "./Pipeable.js";
22
+ import type * as Types from "./Types.js";
23
+ declare const TypeId: unique symbol;
24
+ /**
25
+ * @since 2.0.0
26
+ * @category symbol
27
+ */
28
+ export type TypeId = typeof TypeId;
29
+ /**
30
+ * @since 2.0.0
31
+ * @category models
32
+ */
33
+ export interface Trie<in out Value> extends Iterable<[string, Value]>, Equal, Pipeable, Inspectable {
34
+ readonly [TypeId]: {
35
+ readonly _Value: Types.Covariant<Value>;
36
+ };
37
+ }
38
+ /**
39
+ * Creates an empty `Trie`.
40
+ *
41
+ * @example
42
+ * import * as Trie from "effect/Trie"
43
+ * import * as Equal from "effect/Equal"
44
+ *
45
+ * const trie = Trie.empty<string>()
46
+ *
47
+ * assert.equal(Trie.size(trie), 0)
48
+ * assert.deepStrictEqual(Array.from(trie), [])
49
+ *
50
+ * @since 2.0.0
51
+ * @category constructors
52
+ */
53
+ export declare const empty: <V = never>() => Trie<V>;
54
+ /**
55
+ * Creates a new `Trie` from an iterable collection of key/value pairs (e.g. `Array<[string, V]>`).
56
+ *
57
+ * @example
58
+ * import * as Trie from "effect/Trie"
59
+ * import * as Equal from "effect/Equal"
60
+ *
61
+ * const iterable: Array<readonly [string, number]> = [["call", 0], ["me", 1], ["mind", 2], ["mid", 3]]
62
+ * const trie = Trie.fromIterable(iterable)
63
+ *
64
+ * // The entries in the `Trie` are extracted in alphabetical order, regardless of the insertion order
65
+ * assert.deepStrictEqual(Array.from(trie), [["call", 0], ["me", 1], ["mid", 3], ["mind", 2]])
66
+ * assert.equal(Equal.equals(Trie.make(["call", 0], ["me", 1], ["mind", 2], ["mid", 3]), trie), true)
67
+ *
68
+ * @since 2.0.0
69
+ * @category constructors
70
+ */
71
+ export declare const fromIterable: <V>(entries: Iterable<readonly [string, V]>) => Trie<V>;
72
+ /**
73
+ * Constructs a new `Trie` from the specified entries (`[string, V]`).
74
+ *
75
+ * @example
76
+ * import * as Trie from "effect/Trie"
77
+ * import * as Equal from "effect/Equal"
78
+ *
79
+ * const trie = Trie.make(["ca", 0], ["me", 1])
80
+ *
81
+ * assert.deepStrictEqual(Array.from(trie), [["ca", 0], ["me", 1]])
82
+ * assert.equal(Equal.equals(Trie.fromIterable([["ca", 0], ["me", 1]]), trie), true)
83
+ *
84
+ * @since 2.0.0
85
+ * @category constructors
86
+ */
87
+ export declare const make: <Entries extends Array<readonly [string, any]>>(...entries: Entries) => Trie<Entries[number] extends readonly [any, infer V] ? V : never>;
88
+ /**
89
+ * Insert a new entry in the `Trie`.
90
+ *
91
+ * @example
92
+ * import * as Trie from "effect/Trie"
93
+ *
94
+ * const trie1 = Trie.empty<number>().pipe(
95
+ * Trie.insert("call", 0)
96
+ * )
97
+ * const trie2 = trie1.pipe(Trie.insert("me", 1))
98
+ * const trie3 = trie2.pipe(Trie.insert("mind", 2))
99
+ * const trie4 = trie3.pipe(Trie.insert("mid", 3))
100
+ *
101
+ * assert.deepStrictEqual(Array.from(trie1), [["call", 0]])
102
+ * assert.deepStrictEqual(Array.from(trie2), [["call", 0], ["me", 1]])
103
+ * assert.deepStrictEqual(Array.from(trie3), [["call", 0], ["me", 1], ["mind", 2]])
104
+ * assert.deepStrictEqual(Array.from(trie4), [["call", 0], ["me", 1], ["mid", 3], ["mind", 2]])
105
+ *
106
+ * @since 2.0.0
107
+ * @category mutations
108
+ */
109
+ export declare const insert: {
110
+ <V>(key: string, value: V): (self: Trie<V>) => Trie<V>;
111
+ <V>(self: Trie<V>, key: string, value: V): Trie<V>;
112
+ };
113
+ /**
114
+ * Returns an `IterableIterator` of the keys within the `Trie`.
115
+ *
116
+ * The keys are returned in alphabetical order, regardless of insertion order.
117
+ *
118
+ * @example
119
+ * import * as Trie from "effect/Trie"
120
+ *
121
+ * const trie = Trie.empty<number>().pipe(
122
+ * Trie.insert("cab", 0),
123
+ * Trie.insert("abc", 1),
124
+ * Trie.insert("bca", 2)
125
+ * )
126
+ *
127
+ * const result = Array.from(Trie.keys(trie))
128
+ * assert.deepStrictEqual(result, ["abc", "bca", "cab"])
129
+ *
130
+ * @since 2.0.0
131
+ * @category getters
132
+ */
133
+ export declare const keys: <V>(self: Trie<V>) => IterableIterator<string>;
134
+ /**
135
+ * Returns an `IterableIterator` of the values within the `Trie`.
136
+ *
137
+ * Values are ordered based on their key in alphabetical order, regardless of insertion order.
138
+ *
139
+ * @example
140
+ * import * as Trie from "effect/Trie"
141
+ *
142
+ * const trie = Trie.empty<number>().pipe(
143
+ * Trie.insert("call", 0),
144
+ * Trie.insert("me", 1),
145
+ * Trie.insert("and", 2)
146
+ * )
147
+ *
148
+ * const result = Array.from(Trie.values(trie))
149
+ * assert.deepStrictEqual(result, [2, 0, 1])
150
+ *
151
+ * @since 2.0.0
152
+ * @category getters
153
+ */
154
+ export declare const values: <V>(self: Trie<V>) => IterableIterator<V>;
155
+ /**
156
+ * Returns an `IterableIterator` of the entries within the `Trie`.
157
+ *
158
+ * The entries are returned by keys in alphabetical order, regardless of insertion order.
159
+ *
160
+ * @example
161
+ * import * as Trie from "effect/Trie"
162
+ *
163
+ * const trie = Trie.empty<number>().pipe(
164
+ * Trie.insert("call", 0),
165
+ * Trie.insert("me", 1)
166
+ * )
167
+ *
168
+ * const result = Array.from(Trie.entries(trie))
169
+ * assert.deepStrictEqual(result, [["call", 0], ["me", 1]])
170
+ *
171
+ * @since 2.0.0
172
+ * @category getters
173
+ */
174
+ export declare const entries: <V>(self: Trie<V>) => IterableIterator<[string, V]>;
175
+ /**
176
+ * Returns an `Array<[K, V]>` of the entries within the `Trie`.
177
+ *
178
+ * Equivalent to `Array.from(Trie.entries(trie))`.
179
+ *
180
+ * @example
181
+ * import * as Trie from "effect/Trie"
182
+ *
183
+ * const trie = Trie.empty<number>().pipe(
184
+ * Trie.insert("call", 0),
185
+ * Trie.insert("me", 1)
186
+ * )
187
+ * const result = Trie.toEntries(trie)
188
+ *
189
+ * assert.deepStrictEqual(result, [["call", 0], ["me", 1]])
190
+ *
191
+ * @since 2.0.0
192
+ * @category getters
193
+ */
194
+ export declare const toEntries: <V>(self: Trie<V>) => [string, V][];
195
+ /**
196
+ * Returns an `IterableIterator` of the keys within the `Trie`
197
+ * that have `prefix` as prefix (`prefix` included if it exists).
198
+ *
199
+ * @example
200
+ * import * as Trie from "effect/Trie"
201
+ *
202
+ * const trie = Trie.empty<number>().pipe(
203
+ * Trie.insert("she", 0),
204
+ * Trie.insert("shells", 1),
205
+ * Trie.insert("sea", 2),
206
+ * Trie.insert("shore", 3)
207
+ * )
208
+ *
209
+ * const result = Array.from(Trie.keysWithPrefix(trie, "she"))
210
+ * assert.deepStrictEqual(result, ["she", "shells"])
211
+ *
212
+ * @since 2.0.0
213
+ * @category getters
214
+ */
215
+ export declare const keysWithPrefix: {
216
+ (prefix: string): <V>(self: Trie<V>) => IterableIterator<string>;
217
+ <V>(self: Trie<V>, prefix: string): IterableIterator<string>;
218
+ };
219
+ /**
220
+ * Returns an `IterableIterator` of the values within the `Trie`
221
+ * that have `prefix` as prefix (`prefix` included if it exists).
222
+ *
223
+ * @example
224
+ * import * as Trie from "effect/Trie"
225
+ *
226
+ * const trie = Trie.empty<number>().pipe(
227
+ * Trie.insert("she", 0),
228
+ * Trie.insert("shells", 1),
229
+ * Trie.insert("sea", 2),
230
+ * Trie.insert("shore", 3)
231
+ * )
232
+ *
233
+ * const result = Array.from(Trie.valuesWithPrefix(trie, "she"))
234
+ *
235
+ * // 0: "she", 1: "shells"
236
+ * assert.deepStrictEqual(result, [0, 1])
237
+ *
238
+ * @since 2.0.0
239
+ * @category getters
240
+ */
241
+ export declare const valuesWithPrefix: {
242
+ (prefix: string): <V>(self: Trie<V>) => IterableIterator<V>;
243
+ <V>(self: Trie<V>, prefix: string): IterableIterator<V>;
244
+ };
245
+ /**
246
+ * Returns an `IterableIterator` of the entries within the `Trie`
247
+ * that have `prefix` as prefix (`prefix` included if it exists).
248
+ *
249
+ * @example
250
+ * import * as Trie from "effect/Trie"
251
+ *
252
+ * const trie = Trie.empty<number>().pipe(
253
+ * Trie.insert("she", 0),
254
+ * Trie.insert("shells", 1),
255
+ * Trie.insert("sea", 2),
256
+ * Trie.insert("shore", 3)
257
+ * )
258
+ *
259
+ * const result = Array.from(Trie.entriesWithPrefix(trie, "she"))
260
+ * assert.deepStrictEqual(result, [["she", 0], ["shells", 1]])
261
+ *
262
+ * @since 2.0.0
263
+ * @category getters
264
+ */
265
+ export declare const entriesWithPrefix: {
266
+ (prefix: string): <V>(self: Trie<V>) => IterableIterator<[string, V]>;
267
+ <V>(self: Trie<V>, prefix: string): IterableIterator<[string, V]>;
268
+ };
269
+ /**
270
+ * Returns `Array<[K, V]>` of the entries within the `Trie`
271
+ * that have `prefix` as prefix (`prefix` included if it exists).
272
+ *
273
+ * @example
274
+ * import * as Trie from "effect/Trie"
275
+ *
276
+ * const trie = Trie.empty<number>().pipe(
277
+ * Trie.insert("shells", 0),
278
+ * Trie.insert("sells", 1),
279
+ * Trie.insert("sea", 2),
280
+ * Trie.insert("she", 3)
281
+ * )
282
+ *
283
+ * const result = Trie.toEntriesWithPrefix(trie, "she")
284
+ * assert.deepStrictEqual(result, [["she", 3], ["shells", 0]])
285
+ *
286
+ * @since 2.0.0
287
+ * @category getters
288
+ */
289
+ export declare const toEntriesWithPrefix: {
290
+ (prefix: string): <V>(self: Trie<V>) => Array<[string, V]>;
291
+ <V>(self: Trie<V>, prefix: string): Array<[string, V]>;
292
+ };
293
+ /**
294
+ * Returns the longest key/value in the `Trie`
295
+ * that is a prefix of that `key` if it exists, `None` otherwise.
296
+ *
297
+ * @example
298
+ * import * as Trie from "effect/Trie"
299
+ * import * as Option from "effect/Option"
300
+ *
301
+ * const trie = Trie.empty<number>().pipe(
302
+ * Trie.insert("shells", 0),
303
+ * Trie.insert("sells", 1),
304
+ * Trie.insert("she", 2)
305
+ * )
306
+ *
307
+ * assert.deepStrictEqual(Trie.longestPrefixOf(trie, "sell"), Option.none())
308
+ * assert.deepStrictEqual(Trie.longestPrefixOf(trie, "sells"), Option.some(["sells", 1]))
309
+ * assert.deepStrictEqual(Trie.longestPrefixOf(trie, "shell"), Option.some(["she", 2]))
310
+ * assert.deepStrictEqual(Trie.longestPrefixOf(trie, "shellsort"), Option.some(["shells", 0]))
311
+ *
312
+ * @since 2.0.0
313
+ * @category getters
314
+ */
315
+ export declare const longestPrefixOf: {
316
+ (key: string): <V>(self: Trie<V>) => Option<[string, V]>;
317
+ <V>(self: Trie<V>, key: string): Option<[string, V]>;
318
+ };
319
+ /**
320
+ * Returns the size of the `Trie` (number of entries in the `Trie`).
321
+ *
322
+ * @example
323
+ * import * as Trie from "effect/Trie"
324
+ *
325
+ * const trie = Trie.empty<number>().pipe(
326
+ * Trie.insert("a", 0),
327
+ * Trie.insert("b", 1)
328
+ * )
329
+ *
330
+ * assert.equal(Trie.size(trie), 2)
331
+ *
332
+ * @since 2.0.0
333
+ * @category getters
334
+ */
335
+ export declare const size: <V>(self: Trie<V>) => number;
336
+ /**
337
+ * Safely lookup the value for the specified key in the `Trie`.
338
+ *
339
+ * @example
340
+ * import * as Trie from "effect/Trie"
341
+ * import * as Option from "effect/Option"
342
+ *
343
+ * const trie = Trie.empty<number>().pipe(
344
+ * Trie.insert("call", 0),
345
+ * Trie.insert("me", 1),
346
+ * Trie.insert("mind", 2),
347
+ * Trie.insert("mid", 3)
348
+ * )
349
+ *
350
+ * assert.deepStrictEqual(Trie.get(trie, "call"), Option.some(0))
351
+ * assert.deepStrictEqual(Trie.get(trie, "me"), Option.some(1))
352
+ * assert.deepStrictEqual(Trie.get(trie, "mind"), Option.some(2))
353
+ * assert.deepStrictEqual(Trie.get(trie, "mid"), Option.some(3))
354
+ * assert.deepStrictEqual(Trie.get(trie, "cale"), Option.none())
355
+ * assert.deepStrictEqual(Trie.get(trie, "ma"), Option.none())
356
+ * assert.deepStrictEqual(Trie.get(trie, "midn"), Option.none())
357
+ * assert.deepStrictEqual(Trie.get(trie, "mea"), Option.none())
358
+ *
359
+ * @since 2.0.0
360
+ * @category elements
361
+ */
362
+ export declare const get: {
363
+ (key: string): <V>(self: Trie<V>) => Option<V>;
364
+ <V>(self: Trie<V>, key: string): Option<V>;
365
+ };
366
+ /**
367
+ * Check if the given key exists in the `Trie`.
368
+ *
369
+ * @example
370
+ * import * as Trie from "effect/Trie"
371
+ *
372
+ * const trie = Trie.empty<number>().pipe(
373
+ * Trie.insert("call", 0),
374
+ * Trie.insert("me", 1),
375
+ * Trie.insert("mind", 2),
376
+ * Trie.insert("mid", 3)
377
+ * )
378
+ *
379
+ * assert.equal(Trie.has(trie, "call"), true)
380
+ * assert.equal(Trie.has(trie, "me"), true)
381
+ * assert.equal(Trie.has(trie, "mind"), true)
382
+ * assert.equal(Trie.has(trie, "mid"), true)
383
+ * assert.equal(Trie.has(trie, "cale"), false)
384
+ * assert.equal(Trie.has(trie, "ma"), false)
385
+ * assert.equal(Trie.has(trie, "midn"), false)
386
+ * assert.equal(Trie.has(trie, "mea"), false)
387
+ *
388
+ * @since 2.0.0
389
+ * @category elements
390
+ */
391
+ export declare const has: {
392
+ (key: string): <V>(self: Trie<V>) => boolean;
393
+ <V>(self: Trie<V>, key: string): boolean;
394
+ };
395
+ /**
396
+ * Checks if the `Trie` contains any entries.
397
+ *
398
+ * @example
399
+ * import * as Trie from "effect/Trie"
400
+ *
401
+ * const trie = Trie.empty<number>()
402
+ * const trie1 = trie.pipe(Trie.insert("ma", 0))
403
+ *
404
+ * assert.equal(Trie.isEmpty(trie), true)
405
+ * assert.equal(Trie.isEmpty(trie1), false)
406
+ *
407
+ * @since 2.0.0
408
+ * @category elements
409
+ */
410
+ export declare const isEmpty: <V>(self: Trie<V>) => boolean;
411
+ /**
412
+ * Unsafely lookup the value for the specified key in the `Trie`.
413
+ *
414
+ * `unsafeGet` will throw if the key is not found. Use `get` instead to safely
415
+ * get a value from the `Trie`.
416
+ *
417
+ * @example
418
+ * import * as Trie from "effect/Trie"
419
+ *
420
+ * const trie = Trie.empty<number>().pipe(
421
+ * Trie.insert("call", 0),
422
+ * Trie.insert("me", 1)
423
+ * )
424
+ *
425
+ * assert.throws(() => Trie.unsafeGet(trie, "mae"))
426
+ *
427
+ * @since 2.0.0
428
+ * @category unsafe
429
+ */
430
+ export declare const unsafeGet: {
431
+ (key: string): <V>(self: Trie<V>) => V;
432
+ <V>(self: Trie<V>, key: string): V;
433
+ };
434
+ /**
435
+ * Remove the entry for the specified key in the `Trie`.
436
+ *
437
+ * @example
438
+ * import * as Trie from "effect/Trie"
439
+ * import * as Option from "effect/Option"
440
+ *
441
+ * const trie = Trie.empty<number>().pipe(
442
+ * Trie.insert("call", 0),
443
+ * Trie.insert("me", 1),
444
+ * Trie.insert("mind", 2),
445
+ * Trie.insert("mid", 3)
446
+ * )
447
+ *
448
+ * const trie1 = trie.pipe(Trie.remove("call"))
449
+ * const trie2 = trie1.pipe(Trie.remove("mea"))
450
+ *
451
+ * assert.deepStrictEqual(Trie.get(trie, "call"), Option.some(0))
452
+ * assert.deepStrictEqual(Trie.get(trie1, "call"), Option.none())
453
+ * assert.deepStrictEqual(Trie.get(trie2, "call"), Option.none())
454
+ *
455
+ * @since 2.0.0
456
+ * @category mutations
457
+ */
458
+ export declare const remove: {
459
+ (key: string): <V>(self: Trie<V>) => Trie<V>;
460
+ <V>(self: Trie<V>, key: string): Trie<V>;
461
+ };
462
+ /**
463
+ * Reduce a state over the entries of the `Trie`.
464
+ *
465
+ * @example
466
+ * import * as Trie from "effect/Trie"
467
+ *
468
+ * const trie = Trie.empty<number>().pipe(
469
+ * Trie.insert("shells", 0),
470
+ * Trie.insert("sells", 1),
471
+ * Trie.insert("she", 2)
472
+ * )
473
+ *
474
+ * assert.equal(
475
+ * trie.pipe(
476
+ * Trie.reduce(0, (acc, n) => acc + n)
477
+ * ),
478
+ * 3
479
+ * )
480
+ * assert.equal(
481
+ * trie.pipe(
482
+ * Trie.reduce(10, (acc, n) => acc + n)
483
+ * ),
484
+ * 13
485
+ * )
486
+ * assert.equal(
487
+ * trie.pipe(
488
+ * Trie.reduce("", (acc, _, key) => acc + key)
489
+ * ),
490
+ * "sellssheshells"
491
+ * )
492
+ *
493
+ * @since 2.0.0
494
+ * @category folding
495
+ */
496
+ export declare const reduce: {
497
+ <Z, V>(zero: Z, f: (accumulator: Z, value: V, key: string) => Z): (self: Trie<V>) => Z;
498
+ <Z, V>(self: Trie<V>, zero: Z, f: (accumulator: Z, value: V, key: string) => Z): Z;
499
+ };
500
+ /**
501
+ * Maps over the entries of the `Trie` using the specified function.
502
+ *
503
+ * @example
504
+ * import * as Trie from "effect/Trie"
505
+ * import * as Equal from "effect/Equal"
506
+ *
507
+ * const trie = Trie.empty<number>().pipe(
508
+ * Trie.insert("shells", 0),
509
+ * Trie.insert("sells", 1),
510
+ * Trie.insert("she", 2)
511
+ * )
512
+ *
513
+ * const trieMapV = Trie.empty<number>().pipe(
514
+ * Trie.insert("shells", 1),
515
+ * Trie.insert("sells", 2),
516
+ * Trie.insert("she", 3)
517
+ * )
518
+ *
519
+ * const trieMapK = Trie.empty<number>().pipe(
520
+ * Trie.insert("shells", 6),
521
+ * Trie.insert("sells", 5),
522
+ * Trie.insert("she", 3)
523
+ * )
524
+ *
525
+ * assert.equal(Equal.equals(Trie.map(trie, (v) => v + 1), trieMapV), true)
526
+ * assert.equal(Equal.equals(Trie.map(trie, (_, k) => k.length), trieMapK), true)
527
+ *
528
+ * @since 2.0.0
529
+ * @category folding
530
+ */
531
+ export declare const map: {
532
+ <A, V>(f: (value: V, key: string) => A): (self: Trie<V>) => Trie<A>;
533
+ <V, A>(self: Trie<V>, f: (value: V, key: string) => A): Trie<A>;
534
+ };
535
+ /**
536
+ * Filters entries out of a `Trie` using the specified predicate.
537
+ *
538
+ * @example
539
+ * import * as Trie from "effect/Trie"
540
+ * import * as Equal from "effect/Equal"
541
+ *
542
+ * const trie = Trie.empty<number>().pipe(
543
+ * Trie.insert("shells", 0),
544
+ * Trie.insert("sells", 1),
545
+ * Trie.insert("she", 2)
546
+ * )
547
+ *
548
+ * const trieMapV = Trie.empty<number>().pipe(
549
+ * Trie.insert("she", 2)
550
+ * )
551
+ *
552
+ * const trieMapK = Trie.empty<number>().pipe(
553
+ * Trie.insert("shells", 0),
554
+ * Trie.insert("sells", 1)
555
+ * )
556
+ *
557
+ * assert.equal(Equal.equals(Trie.filter(trie, (v) => v > 1), trieMapV), true)
558
+ * assert.equal(Equal.equals(Trie.filter(trie, (_, k) => k.length > 3), trieMapK), true)
559
+ *
560
+ * @since 2.0.0
561
+ * @category filtering
562
+ */
563
+ export declare const filter: {
564
+ <A, B extends A>(f: (a: A, k: string) => a is B): (self: Trie<A>) => Trie<B>;
565
+ <B extends A, A = B>(f: (a: A, k: string) => boolean): (self: Trie<B>) => Trie<B>;
566
+ <A, B extends A>(self: Trie<A>, f: (a: A, k: string) => a is B): Trie<B>;
567
+ <A>(self: Trie<A>, f: (a: A, k: string) => boolean): Trie<A>;
568
+ };
569
+ /**
570
+ * Maps over the entries of the `Trie` using the specified partial function
571
+ * and filters out `None` values.
572
+ *
573
+ * @example
574
+ * import * as Trie from "effect/Trie"
575
+ * import * as Equal from "effect/Equal"
576
+ * import * as Option from "effect/Option"
577
+ *
578
+ * const trie = Trie.empty<number>().pipe(
579
+ * Trie.insert("shells", 0),
580
+ * Trie.insert("sells", 1),
581
+ * Trie.insert("she", 2)
582
+ * )
583
+ *
584
+ * const trieMapV = Trie.empty<number>().pipe(
585
+ * Trie.insert("she", 2)
586
+ * )
587
+ *
588
+ * const trieMapK = Trie.empty<number>().pipe(
589
+ * Trie.insert("shells", 0),
590
+ * Trie.insert("sells", 1)
591
+ * )
592
+ *
593
+ * assert.equal(Equal.equals(Trie.filterMap(trie, (v) => v > 1 ? Option.some(v) : Option.none()), trieMapV), true)
594
+ * assert.equal(
595
+ * Equal.equals(Trie.filterMap(trie, (v, k) => k.length > 3 ? Option.some(v) : Option.none()), trieMapK),
596
+ * true
597
+ * )
598
+ *
599
+ * @since 2.0.0
600
+ * @category filtering
601
+ */
602
+ export declare const filterMap: {
603
+ <A, B>(f: (value: A, key: string) => Option<B>): (self: Trie<A>) => Trie<B>;
604
+ <A, B>(self: Trie<A>, f: (value: A, key: string) => Option<B>): Trie<B>;
605
+ };
606
+ /**
607
+ * Filters out `None` values from a `Trie` of `Options`s.
608
+ *
609
+ * @example
610
+ * import * as Trie from "effect/Trie"
611
+ * import * as Equal from "effect/Equal"
612
+ * import * as Option from "effect/Option"
613
+ *
614
+ * const trie = Trie.empty<Option.Option<number>>().pipe(
615
+ * Trie.insert("shells", Option.some(0)),
616
+ * Trie.insert("sells", Option.none()),
617
+ * Trie.insert("she", Option.some(2))
618
+ * )
619
+ *
620
+ * const trieMapV = Trie.empty<number>().pipe(
621
+ * Trie.insert("shells", 0),
622
+ * Trie.insert("she", 2)
623
+ * )
624
+ *
625
+ * assert.equal(Equal.equals(Trie.compact(trie), trieMapV), true)
626
+ *
627
+ * @since 2.0.0
628
+ * @category filtering
629
+ */
630
+ export declare const compact: <A>(self: Trie<Option<A>>) => Trie<A>;
631
+ /**
632
+ * Applies the specified function to the entries of the `Trie`.
633
+ *
634
+ * @example
635
+ * import * as Trie from "effect/Trie"
636
+ *
637
+ * let value = 0
638
+ *
639
+ * Trie.empty<number>().pipe(
640
+ * Trie.insert("shells", 0),
641
+ * Trie.insert("sells", 1),
642
+ * Trie.insert("she", 2),
643
+ * Trie.forEach((n, key) => {
644
+ * value += n + key.length
645
+ * })
646
+ * )
647
+ *
648
+ * assert.equal(value, 17)
649
+ *
650
+ * @since 2.0.0
651
+ * @category traversing
652
+ */
653
+ export declare const forEach: {
654
+ <V>(f: (value: V, key: string) => void): (self: Trie<V>) => void;
655
+ <V>(self: Trie<V>, f: (value: V, key: string) => void): void;
656
+ };
657
+ /**
658
+ * Updates the value of the specified key within the `Trie` if it exists.
659
+ *
660
+ * @example
661
+ * import * as Trie from "effect/Trie"
662
+ * import * as Equal from "effect/Equal"
663
+ * import * as Option from "effect/Option"
664
+ *
665
+ * const trie = Trie.empty<number>().pipe(
666
+ * Trie.insert("shells", 0),
667
+ * Trie.insert("sells", 1),
668
+ * Trie.insert("she", 2)
669
+ * )
670
+ *
671
+ * assert.deepStrictEqual(trie.pipe(Trie.modify("she", (v) => v + 10), Trie.get("she")), Option.some(12))
672
+ *
673
+ * assert.equal(Equal.equals(trie.pipe(Trie.modify("me", (v) => v)), trie), true)
674
+ *
675
+ * @since 2.0.0
676
+ * @category mutations
677
+ */
678
+ export declare const modify: {
679
+ <V>(key: string, f: (v: V) => V): (self: Trie<V>) => Trie<V>;
680
+ <V>(self: Trie<V>, key: string, f: (v: V) => V): Trie<V>;
681
+ };
682
+ /**
683
+ * Removes all entries in the `Trie` which have the specified keys.
684
+ *
685
+ * @example
686
+ * import * as Trie from "effect/Trie"
687
+ * import * as Equal from "effect/Equal"
688
+ *
689
+ * const trie = Trie.empty<number>().pipe(
690
+ * Trie.insert("shells", 0),
691
+ * Trie.insert("sells", 1),
692
+ * Trie.insert("she", 2)
693
+ * )
694
+ *
695
+ * assert.equal(
696
+ * Equal.equals(trie.pipe(Trie.removeMany(["she", "sells"])), Trie.empty<number>().pipe(Trie.insert("shells", 0))),
697
+ * true
698
+ * )
699
+ *
700
+ * @since 2.0.0
701
+ * @category mutations
702
+ */
703
+ export declare const removeMany: {
704
+ (keys: Iterable<string>): <V>(self: Trie<V>) => Trie<V>;
705
+ <V>(self: Trie<V>, keys: Iterable<string>): Trie<V>;
706
+ };
707
+ /**
708
+ * Insert multiple entries in the `Trie` at once.
709
+ *
710
+ * @example
711
+ * import * as Trie from "effect/Trie"
712
+ * import * as Equal from "effect/Equal"
713
+ *
714
+ * const trie = Trie.empty<number>().pipe(
715
+ * Trie.insert("shells", 0),
716
+ * Trie.insert("sells", 1),
717
+ * Trie.insert("she", 2)
718
+ * )
719
+ *
720
+ * const trieInsert = Trie.empty<number>().pipe(
721
+ * Trie.insert("shells", 0),
722
+ * Trie.insertMany(
723
+ * [["sells", 1], ["she", 2]]
724
+ * )
725
+ * )
726
+ *
727
+ * assert.equal(
728
+ * Equal.equals(trie, trieInsert),
729
+ * true
730
+ * )
731
+ *
732
+ * @since 2.0.0
733
+ * @category mutations
734
+ */
735
+ export declare const insertMany: {
736
+ <V>(iter: Iterable<[string, V]>): (self: Trie<V>) => Trie<V>;
737
+ <V>(self: Trie<V>, iter: Iterable<[string, V]>): Trie<V>;
738
+ };
739
+ export {};
740
+ //# sourceMappingURL=Trie.d.ts.map