Skip to content

Map

Immutable key-value map operations. All functions return new maps — they never mutate the original.

FunctionSignatureDescription
Map.empty() -> Map<K, V>Create an empty map
Map.fromArrayArray<(K, V)> -> Map<K, V>Create a map from key-value pairs
Map.getMap<K, V>, K -> Option<V>Look up a value by key
Map.setMap<K, V>, K, V -> Map<K, V>Add or update a key-value pair
Map.removeMap<K, V>, K -> Map<K, V>Remove a key-value pair
Map.hasMap<K, V>, K -> booleanCheck if a key exists
Map.keysMap<K, V> -> Array<K>Get all keys
Map.valuesMap<K, V> -> Array<V>Get all values
Map.entriesMap<K, V> -> Array<(K, V)>Get all key-value pairs
Map.sizeMap<K, V> -> numberNumber of entries
Map.isEmptyMap<K, V> -> booleanTrue if map has no entries
Map.mergeMap<K, V>, Map<K, V> -> Map<K, V>Merge two maps (second wins on conflict)
// Create a map from key-value pairs
const config = Map.fromArray([("host", "localhost"), ("port", "8080")])
// All operations are immutable
const updated = config
|> Map.set("port", "3000")
|> Map.set("debug", "true")
// Safe lookup returns Option
const port = Map.get(config, "port") // Some("8080")
const missing = Map.get(config, "foo") // None
// Check membership
const hasHost = config |> Map.has("host") // true
// Convert to arrays
const keys = config |> Map.keys // ["host", "port"]
const values = config |> Map.values // ["localhost", "8080"]
// Merge maps (second map's values win on key conflict)
const defaults = Map.fromArray([("port", "80"), ("host", "0.0.0.0")])
const merged = Map.merge(defaults, config)
// Map { "port" => "8080", "host" => "localhost" }