HashMap
HashMap module: persistent hash-array-mapped-trie map.
HashMap(k, v) is an immutable, hash-indexed key-value store. Unlike Map(k, v), no comparator is needed: key equality uses structural == and hashing uses the built-in polymorphic hash.
Performance (n entries): get / put / delete O(log₃₂ n) ≈ O(1) size / fold / keys O(n)
Key order is hash-traversal order (not insertion order, not sorted). Use Map if you need sorted iteration or Ord-derived equality.
Types
Functions
Removes a key from the map. Returns the map unchanged if key is absent.
march> HashMap.has(HashMap.delete(HashMap.put(HashMap.new(), "a", 1), "a"), "a")
falseReturns all (key, value) pairs as a list (hash-traversal order).
Returns a map containing only entries where pred(key)(value) is true. pred : k -> v -> Bool (curried).
Left fold over all entries. f is called as f(acc, key, value) -> new_acc. Iteration order is hash-traversal order (not sorted, not insertion order).
Builds a HashMap from a list of (key, value) pairs. Later entries overwrite earlier ones for duplicate keys.
march> HashMap.size(HashMap.from_list([("a",1),("b",2),("a",99)]))
2Returns Some(value) if key is present, or None.
march> HashMap.get(HashMap.new(), "missing")
NoneReturns the value for key, or default if the key is absent.
Returns true if key is present.
Returns true if the map contains no entries.
Returns all keys as a list (hash-traversal order).
Applies f to each value, returning a new map with the same keys.
Merges two maps. When a key appears in both, the value from b takes precedence. O(n log n) in the size of b.
Merges two maps with a combining function for conflicting keys. When key exists in both, value is f(val_from_a)(val_from_b). f : v -> v -> v (curried).
Returns an empty HashMap. No comparator needed.
march> HashMap.is_empty(HashMap.new())
trueInserts or replaces a key-value pair. Returns the new map.
march> HashMap.get(HashMap.put(HashMap.new(), "a", 1), "a")
Some(1)Returns the number of key-value pairs. O(n).
Converts a HashMap to a list of (key, value) pairs (hash-traversal order).
Updates a key using a function from Option(v) -> v. None is passed when the key is absent; Some(existing) when present. The function's return value becomes the new value for that key.
march> HashMap.get(HashMap.update(HashMap.new(), "k", fn _ -> 42), "k")
Some(42)Returns all values as a list (hash-traversal order).