Std. Map
(Cure Standard Library v0.37.2)
View Source
Map operations: get, put, delete, keys, values, merge.
Thin wrapper around Erlang's :maps module with one Cure-level
default-aware getter (get_or/3) and trivial helpers
(is_empty/1, count/1).
Examples
use Std.Map
let m = put(:age, 42, put(:name, "Ada", new()))
size(m) # => 2
get(:name, m) # => "Ada"
get_or(:height, m, 0) # => 0use Std.Map
# Right-biased merge: values in the second map win.
let a = from_list([%[:x, 1], %[:y, 2]])
let b = from_list([%[:y, 20], %[:z, 30]])
merge(a, b)
# => #{x: 1, y: 20, z: 30}
Summary
Functions
Alias for size/1; reads better in some contexts.
Build a map from a list of %[key, value] tuples.
Look up key. Raises :badkey if missing; use get_or/3 for a
total variant.
Look up key, returning default when missing.
true when key is a member of map.
true when map has no entries.
List of keys.
Right-biased merge: keys in map2 override map1.
New empty map.
Return a new map with key set to value (replaces any
existing entry).
Return map without key.
Number of entries in map.
List of %[key, value] tuples.
List of values.
Functions
fn count(map: Map(k, v)) -> Int
Alias for size/1; reads better in some contexts.
fn from_list(list: List(Tuple)) -> Map(k, v)
Build a map from a list of %[key, value] tuples.
fn get(key: k, map: Map(k, v)) -> v
Look up key. Raises :badkey if missing; use get_or/3 for a
total variant.
fn get_or(key: k, map: Map(k, v), default: v) -> v
Look up key, returning default when missing.
fn has_key(key: k, map: Map(k, v)) -> Bool
true when key is a member of map.
fn is_empty(map: Map(k, v)) -> Bool
true when map has no entries.
fn keys(map: Map(k, v)) -> List(k)
List of keys.
fn merge(map1: Map(k, v), map2: Map(k, v)) -> Map(k, v)
Right-biased merge: keys in map2 override map1.
fn new() -> Map(k, v)
New empty map.
fn put(key: k, value: v, map: Map(k, v)) -> Map(k, v)
Return a new map with key set to value (replaces any
existing entry).
fn remove(key: k, map: Map(k, v)) -> Map(k, v)
Return map without key.
fn size(map: Map(k, v)) -> Int
Number of entries in map.
fn to_list(map: Map(k, v)) -> List(Tuple)
List of %[key, value] tuples.
fn values(map: Map(k, v)) -> List(v)
List of values.