Package: effect
Module: TxHashMap
Merges another HashMap into this TxHashMap. If both maps contain the same key, the value from the other map will be used.
Details
This function mutates the original TxHashMap by merging the provided HashMap into it. It does not return a new TxHashMap reference.
Example (Merging HashMaps)
import { Effect, HashMap, TxHashMap } from "effect"
const program = Effect.gen(function*() {
// Create initial user preferences
const userPrefs = yield* TxHashMap.make(
["theme", "light"],
["language", "en"],
["notifications", "enabled"]
)
// New preferences to merge in
const newSettings = HashMap.make(
["theme", "dark"], // will override existing
["timezone", "UTC"], // new setting
["sound", "enabled"] // new setting
)
// Merge the new settings
yield* TxHashMap.union(userPrefs, newSettings)
// Check the merged result
const theme = yield* TxHashMap.get(userPrefs, "theme")
console.log(theme) // Option.some("dark") - overridden
const language = yield* TxHashMap.get(userPrefs, "language")
console.log(language) // Option.some("en") - preserved
const timezone = yield* TxHashMap.get(userPrefs, "timezone")
console.log(timezone) // Option.some("UTC") - newly added
const size = yield* TxHashMap.size(userPrefs)
console.log(size) // 5 total settings
})
Signature
declare const union: { <K1 extends K, K, V1 extends V, V>(other: HashMap.HashMap<K1, V1>): (self: TxHashMap<K, V>) => Effect.Effect<void>; <K1 extends K, K, V1 extends V, V>(self: TxHashMap<K, V>, other: HashMap.HashMap<K1, V1>): Effect.Effect<void>; }
Since v4.0.0