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
use 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}
Group tag consumed by Cure.Stdlib.Preload.
The map carrier, indexed by its key and value types. Map(k, v)
is the Idris (SortedMap k v) / Haskell (Map k v) design: the
index makes get's result type recoverable (no return-polymorphism
wall) and, in turn, lets map patterns bind values at a known type.
Maps are homogeneous in their values; a genuinely heterogeneous map
uses Map(k, Any). The index is purely type-level — Map(k, v)
still erases to a raw BEAM map and the :maps externs are unchanged.
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) extern
Build a map from a list of
%[key, value]tuples. -
# fn get(key: k, map: Map(k, v)) -> v extern
Look up
key. Raises:badkeyif missing; useget_or/3for a total variant. -
# fn get_or(key: k, map: Map(k, v), default: v) -> v
Look up
key, returningdefaultwhen missing. -
# fn has_key(key: k, map: Map(k, v)) -> Bool extern
truewhenkeyis a member ofmap. -
# fn is_empty(map: Map(k, v)) -> Bool
truewhenmaphas no entries. -
# fn keys(map: Map(k, v)) -> List(k) extern
List of keys.
-
# fn merge(map1: Map(k, v), map2: Map(k, v)) -> Map(k, v) extern
Right-biased merge: keys in
map2overridemap1. -
# fn new() -> Map(k, v) extern
New empty map.
-
# fn put(key: k, value: v, map: Map(k, v)) -> Map(k, v) extern
Return a new map with
keyset tovalue(replaces any existing entry). -
# fn remove(key: k, map: Map(k, v)) -> Map(k, v) extern
Return
mapwithoutkey. -
# fn size(map: Map(k, v)) -> Int extern
Number of entries in
map. -
# fn to_list(map: Map(k, v)) -> List(Tuple) extern
List of
%[key, value]tuples. -
# fn values(map: Map(k, v)) -> List(v) extern
List of values.