Hyperlinkv0.8.0-beta.28

TxHashMap

TxHashMap.hasconsteffect/TxHashMap.ts:466
<K1 extends K, K>(key: K1): <V>(
  self: TxHashMap<K, V>
) => Effect.Effect<boolean>
<K1 extends K, K, V>(
  self: TxHashMap<K, V>,
  key: K1
): Effect.Effect<boolean>

Checks whether the specified key exists in the TxHashMap.

Example (Checking for keys)

import { Effect, TxHashMap } from "effect"

const program = Effect.gen(function*() {
  const permissions = yield* TxHashMap.make(
    ["alice", ["read", "write"]],
    ["bob", ["read"]],
    ["charlie", ["admin"]]
  )

  // Check if users exist
  const hasAlice = yield* TxHashMap.has(permissions, "alice")
  console.log(hasAlice) // true

  const hasDavid = yield* TxHashMap.has(permissions, "david")
  console.log(hasDavid) // false

  // Use direct method call for type-safe access
  const hasBob = yield* TxHashMap.has(permissions, "bob")
  console.log(hasBob) // true
})
combinators
export const has: {
  <K1 extends K, K>(key: K1): <V>(self: TxHashMap<K, V>) => Effect.Effect<boolean>
  <K1 extends K, K, V>(self: TxHashMap<K, V>, key: K1): Effect.Effect<boolean>
} = dual(
  2,
  <K1 extends K, K, V>(self: TxHashMap<K, V>, key: K1): Effect.Effect<boolean> =>
    Effect.gen(function*() {
      const map = yield* TxRef.get(self.ref)
      return HashMap.has(map, key)
    })
)