Skip to main content
HashMap is an immutable hash-based map data structure.

Type Definition

interface HashMap<K, V> extends Iterable<[K, V]>

Constructors

empty

Creates an empty HashMap.
const empty: <K = never, V = never>() => HashMap<K, V>

make

Creates a HashMap from entries.
const make: <Entries extends ReadonlyArray<readonly [any, any]>>(...entries: Entries) => HashMap<Entries[number][0], Entries[number][1]>

fromIterable

Creates a HashMap from an iterable of key-value pairs.
const fromIterable: <K, V>(iterable: Iterable<readonly [K, V]>) => HashMap<K, V>

Operations

set

Sets a key-value pair.
const set: <K, V>(key: K, value: V) => (self: HashMap<K, V>) => HashMap<K, V>

get

Retrieves a value by key.
const get: <K>(key: K) => <V>(self: HashMap<K, V>) => Option<V>

remove

Removes a key.
const remove: <K>(key: K) => <V>(self: HashMap<K, V>) => HashMap<K, V>

Example

import { HashMap } from "effect"

const map = HashMap.make(["a", 1], ["b", 2]).pipe(
  HashMap.set("c", 3)
)

console.log(HashMap.get(map, "b")) // Some(2)

Build docs developers (and LLMs) love