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

cure
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
cure
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 :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 extern

    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) extern

    List of keys.

  • # fn merge(map1: Map(k, v), map2: Map(k, v)) -> Map(k, v) extern

    Right-biased merge: keys in map2 override map1.

  • # 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 key set to value (replaces any existing entry).

  • # fn remove(key: k, map: Map(k, v)) -> Map(k, v) extern

    Return map without key.

  • # 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.