Hyperlinkv0.8.0-beta.28

TxHashMap

TxHashMap.isEmptyconsteffect/TxHashMap.ts:643
<K, V>(self: TxHashMap<K, V>): Effect.Effect<boolean>

Checks whether the TxHashMap is empty.

Example (Checking for an empty map)

import { Effect, TxHashMap } from "effect"

const program = Effect.gen(function*() {
  // Start with empty map
  const cache = yield* TxHashMap.empty<string, any>()
  const empty = yield* TxHashMap.isEmpty(cache)
  console.log(empty) // true

  // Add an item
  yield* TxHashMap.set(cache, "key1", "value1")
  const stillEmpty = yield* TxHashMap.isEmpty(cache)
  console.log(stillEmpty) // false

  // Clear and check again
  yield* TxHashMap.clear(cache)
  const emptyAgain = yield* TxHashMap.isEmpty(cache)
  console.log(emptyAgain) // true
})
combinators
export const isEmpty = <K, V>(self: TxHashMap<K, V>): Effect.Effect<boolean> =>
  Effect.gen(function*() {
    const map = yield* TxRef.get(self.ref)
    return HashMap.isEmpty(map)
  })
Referenced by 1 symbols