effect 2.0.3 → 2.0.4

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