Hyperlinkv0.8.0-beta.28

HashMap

HashMap.hasHashconsteffect/HashMap.ts:475
<K1 extends K, K>(key: K1, hash: number): <V>(
  self: HashMap<K, V>
) => boolean
<K1 extends K, K, V>(self: HashMap<K, V>, key: K1, hash: number): boolean

Checks whether the specified key has an entry in the HashMap using a custom hash.

Example (Checking keys with a hash)

import { Hash, HashMap } from "effect"

// Create a map with case-sensitive keys
const userMap = HashMap.make(
  ["Admin", { role: "administrator" }],
  ["User", { role: "standard" }]
)

// Check with exact hash
const exactHash = Hash.string("Admin")
console.log(HashMap.hasHash(userMap, "Admin", exactHash)) // true

// A matching hash does not override key equality
console.log(HashMap.hasHash(userMap, "admin", exactHash)) // false

// A different hash also cannot find the existing key
const lowercaseHash = Hash.string("admin")
console.log(HashMap.hasHash(userMap, "Admin", lowercaseHash)) // false
elements
Source effect/HashMap.ts:4754 lines
export const hasHash: {
  <K1 extends K, K>(key: K1, hash: number): <V>(self: HashMap<K, V>) => boolean
  <K1 extends K, K, V>(self: HashMap<K, V>, key: K1, hash: number): boolean
} = internal.hasHash
Referenced by 1 symbols