<V>(self: Trie<V>): Array<[string, V]>Returns an Array<[string, V]> of the entries within the Trie.
Details
Equivalent to Array.from(Trie.entries(trie)).
Example (Converting entries to an array)
import { Trie } from "effect"
import * as assert from "node:assert"
const trie = Trie.empty<number>().pipe(
Trie.insert("call", 0),
Trie.insert("me", 1)
)
const result = Trie.toEntries(trie)
assert.deepStrictEqual(result, [["call", 0], ["me", 1]])export const const toEntries: <V>(
self: Trie<V>
) => Array<[string, V]>
Returns an Array<[string, V]> of the entries within the Trie.
Details
Equivalent to Array.from(Trie.entries(trie)).
Example (Converting entries to an array)
import { Trie } from "effect"
import * as assert from "node:assert"
const trie = Trie.empty<number>().pipe(
Trie.insert("call", 0),
Trie.insert("me", 1)
)
const result = Trie.toEntries(trie)
assert.deepStrictEqual(result, [["call", 0], ["me", 1]])
toEntries = <function (type parameter) V in <V>(self: Trie<V>): Array<[string, V]>V>(self: Trie<V>(parameter) self: {
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
self: 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>(self: Trie<V>): Array<[string, V]>V>): interface Array<T>Array<[string, function (type parameter) V in <V>(self: Trie<V>): Array<[string, V]>V]> => var Array: ArrayConstructorArray.ArrayConstructor.from<[string, V]>(iterable: Iterable<[string, V]> | ArrayLike<[string, V]>): [string, V][] (+3 overloads)Creates an array from an iterable object.
from(const entries: <V>(
self: Trie<V>
) => IterableIterator<[string, V]>
Returns an IterableIterator of the entries within the Trie.
Details
The entries are returned by keys in alphabetical order, regardless of insertion order.
Example (Reading entries in alphabetical order)
import { Trie } from "effect"
import * as assert from "node:assert"
const trie = Trie.empty<number>().pipe(
Trie.insert("call", 0),
Trie.insert("me", 1)
)
const result = Array.from(Trie.entries(trie))
assert.deepStrictEqual(result, [["call", 0], ["me", 1]])
entries(self: Trie<V>(parameter) self: {
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
self))