Package: effect
Module: TxHashMap
Creates a TxHashMap from an iterable of key-value pairs.
Example (Creating a map from an iterable)
import { Effect, TxHashMap } from "effect"
const program = Effect.gen(function*() {
// Create from various iterable sources
const configEntries = [
["database.host", "localhost"],
["database.port", "5432"],
["cache.enabled", "true"],
["logging.level", "info"]
] as const
const configMap = yield* TxHashMap.fromIterable(configEntries)
// Verify the configuration was loaded
const size = yield* TxHashMap.size(configMap)
console.log(size) // 4
const dbHost = yield* TxHashMap.get(configMap, "database.host")
console.log(dbHost) // Option.some("localhost")
// Can also create from Map, Set of tuples, etc.
const jsMap = new Map([["key1", "value1"], ["key2", "value2"]])
const txMapFromJs = yield* TxHashMap.fromIterable(jsMap)
})
Signature
declare const fromIterable: <K, V>(entries: Iterable<readonly [K, V]>) => Effect.Effect<TxHashMap<K, V>>
Since v2.0.0