Hyperlinkv0.8.0-beta.28

TxHashMap

TxHashMap.makeconsteffect/TxHashMap.ts:292
<K, V>(...entries: Array<readonly [K, V]>): Effect.Effect<TxHashMap<K, V>>

Creates a TxHashMap from the provided key-value pairs.

Example (Creating a map from entries)

import { Effect, TxHashMap } from "effect"

const program = Effect.gen(function*() {
  // Create a user directory
  const userMap = yield* TxHashMap.make(
    ["alice", { name: "Alice Smith", role: "admin" }],
    ["bob", { name: "Bob Johnson", role: "user" }],
    ["charlie", { name: "Charlie Brown", role: "user" }]
  )

  // Check the initial size
  const size = yield* TxHashMap.size(userMap)
  console.log(size) // 3

  // Access users
  const alice = yield* TxHashMap.get(userMap, "alice")
  console.log(alice) // Option.some({ name: "Alice Smith", role: "admin" })

  const nonExistent = yield* TxHashMap.get(userMap, "david")
  console.log(nonExistent) // Option.none()
})
constructors
export const make = <K, V>(
  ...entries: Array<readonly [K, V]>
): Effect.Effect<TxHashMap<K, V>> =>
  Effect.gen(function*() {
    const hashMap = HashMap.make(...entries)
    const ref = yield* TxRef.make(hashMap)
    return Object.assign(Object.create(TxHashMapProto), { ref })
  })