Std.Map
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) # => 0
# 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}
Functions
-
# fn __group__() -> Atom
Group tag consumed by
Cure.Stdlib.Preload. -
# fn count(map: Map(Any, Any)) -> Int
Alias for
size/1; reads better in some contexts. -
# fn from_list(list: List(Tuple)) -> Map(Any, Any) extern
Build a map from a list of
%[key, value]tuples. -
# fn get(key: K, map: Map(Any, Any)) -> V extern
Look up
key. Raises:badkeyif missing; useget_or/3for a total variant. -
# fn get_or(key: K, map: Map(Any, Any), default: V) -> V
Look up
key, returningdefaultwhen missing. -
# fn has_key(key: K, map: Map(Any, Any)) -> Bool extern
truewhenkeyis a member ofmap. -
# fn is_empty(map: Map(Any, Any)) -> Bool
truewhenmaphas no entries. -
# fn keys(map: Map(Any, Any)) -> List(K) extern
List of keys.
-
# fn merge(map1: Map(Any, Any), map2: Map(Any, Any)) -> Map(Any, Any) extern
Right-biased merge: keys in
map2overridemap1. -
# fn new() -> Map(Any, Any) extern
New empty map.
-
# fn put(key: K, value: V, map: Map(Any, Any)) -> Map(Any, Any) extern
Return a new map with
keyset tovalue(replaces any existing entry). -
# fn remove(key: K, map: Map(Any, Any)) -> Map(Any, Any) extern
Return
mapwithoutkey. -
# fn size(map: Map(Any, Any)) -> Int extern
Number of entries in
map. -
# fn to_list(map: Map(Any, Any)) -> List(Tuple) extern
List of
%[key, value]tuples. -
# fn values(map: Map(Any, Any)) -> List(V) extern
List of values.