Hyperlinkv0.8.0-beta.28

HashMap

HashMap.getHashconsteffect/HashMap.ts:367
<K1 extends K, K>(key: K1, hash: number): <V>(
  self: HashMap<K, V>
) => Option<V>
<K1 extends K, K, V>(
  self: HashMap<K, V>,
  key: K1,
  hash: number
): Option<V>

Looks up the value for the specified key in the HashMap safely using a custom hash.

Example (Looking up values with a hash)

import { Hash, HashMap } from "effect"

// Useful when implementing custom equality for complex keys
const userMap = HashMap.make(
  ["user123", { name: "Alice", role: "admin" }],
  ["user456", { name: "Bob", role: "user" }]
)

// Use precomputed hash for performance in hot paths
const userId = "user123"
const precomputedHash = Hash.string(userId)

// Lookup with custom hash (e.g., cached hash value)
const user = HashMap.getHash(userMap, userId, precomputedHash)
console.log(user) // Option.some({ name: "Alice", role: "admin" })

// This avoids recomputing the hash when you already have it
const notFound = HashMap.getHash(userMap, "user999", Hash.string("user999"))
console.log(notFound) // Option.none()
elements
Source effect/HashMap.ts:3674 lines
export const getHash: {
  <K1 extends K, K>(key: K1, hash: number): <V>(self: HashMap<K, V>) => Option<V>
  <K1 extends K, K, V>(self: HashMap<K, V>, key: K1, hash: number): Option<V>
} = internal.getHash
Referenced by 1 symbols