<V = never>(): Trie<V>Creates an empty Trie.
Example (Creating an empty trie)
import { Trie } from "effect"
import * as assert from "node:assert"
const trie = Trie.empty<string>()
assert.equal(Trie.size(trie), 0)
assert.deepStrictEqual(Array.from(trie), [])constructors
Source effect/Trie.ts:881 lines
export const const empty: <V = never>() => Trie<V>Creates an empty Trie.
Example (Creating an empty trie)
import { Trie } from "effect"
import * as assert from "node:assert"
const trie = Trie.empty<string>()
assert.equal(Trie.size(trie), 0)
assert.deepStrictEqual(Array.from(trie), [])
empty: <function (type parameter) V in <V = never>(): Trie<V>V = never>() => interface Trie<in out Value>An immutable string-keyed map optimized for prefix lookup. Iteration yields
[key, value] pairs in key order, and update operations such as insert and
remove return new Trie values.
Example (Using a trie for prefix search)
import { Trie } from "effect"
// Create a trie with string-to-number mappings
const trie: Trie.Trie<number> = Trie.make(
["apple", 1],
["app", 2],
["application", 3],
["banana", 4]
)
// Get values by exact key
console.log(Trie.get(trie, "apple")) // Some(1)
console.log(Trie.get(trie, "grape")) // None
// Find all keys with a prefix
console.log(Array.from(Trie.keysWithPrefix(trie, "app")))
// ["app", "apple", "application"]
// Iterate over all entries (sorted alphabetically)
for (const [key, value] of trie) {
console.log(`${key}: ${value}`)
}
// Output: "app: 2", "apple: 1", "application: 3", "banana: 4"
// Check if key exists
console.log(Trie.has(trie, "app")) // true
// Get size
console.log(Trie.size(trie)) // 4
Trie<function (type parameter) V in <V = never>(): Trie<V>V> = import TRTR.const empty: <V = never>() => TR.Trie<V>empty