Hyperlinkv0.8.0-beta.28

TxHashMap

TxHashMap.emptyconsteffect/TxHashMap.ts:254
<K, V>(): Effect.Effect<TxHashMap<K, V>>

Creates an empty TxHashMap.

Example (Creating an empty map)

import { Effect, TxHashMap } from "effect"

const program = Effect.gen(function*() {
  // Create an empty transactional hash map
  const emptyMap = yield* TxHashMap.empty<string, number>()

  // Verify it's empty
  const isEmpty = yield* TxHashMap.isEmpty(emptyMap)
  console.log(isEmpty) // true

  const size = yield* TxHashMap.size(emptyMap)
  console.log(size) // 0

  // Start adding elements
  yield* TxHashMap.set(emptyMap, "first", 1)
  const newSize = yield* TxHashMap.size(emptyMap)
  console.log(newSize) // 1
})
constructors
export const empty = <K, V>(): Effect.Effect<TxHashMap<K, V>> =>
  Effect.gen(function*() {
    const ref = yield* TxRef.make(HashMap.empty<K, V>())
    return Object.assign(Object.create(TxHashMapProto), { ref })
  })
Referenced by 1 symbols