Package: effect
Module: HashMap
Looks up the value for the specified key in the HashMap unsafely using the
internal hashing function.
When to use
Use when reading from a HashMap by a key known to exist, and throwing is an
acceptable programming error for a missing key.
Gotchas
This function throws an error if the key is not found. Use HashMap.get for
safe access that returns Option.
Example (Unsafely looking up values)
import { HashMap, Option } from "effect"
const config = HashMap.make(
["api_url", "https://api.example.com"],
["timeout", "5000"],
["retries", "3"]
)
// Safe: use when you're certain the key exists
const apiUrl = HashMap.getUnsafe(config, "api_url") // "https://api.example.com"
console.log(`Connecting to: ${apiUrl}`)
// Preferred: use get() for uncertain keys
const dbUrl = HashMap.get(config, "db_url") // Option.none()
if (Option.isSome(dbUrl)) {
console.log(`Database: ${dbUrl.value}`)
}
// This would throw: HashMap.getUnsafe(config, "db_url")
// Error: "HashMap.getUnsafe: key not found"
Signature
declare const getUnsafe: { <K1 extends K, K>(key: K1): <V>(self: HashMap<K, V>) => V; <K1 extends K, K, V>(self: HashMap<K, V>, key: K1): V; }
Since v4.0.0