gossamer/map

Types

A JS Map holding key-value pairs. Supports any key type (unlike plain objects) and preserves insertion order. Mutable — methods modify the map in place and return it for chaining.

For most Gleam use cases, prefer gleam/dict.Dict. This binding exists for JS interop where a JS Map is specifically required.

Object keys (records, lists, tuples) are matched by JS reference identity, not value equality — two equal-by-value tuples constructed separately are distinct keys. Primitive keys (Int, Float, String, Bool) use value equality.

See Map on MDN.

pub type Map(key, value)

Values

pub fn clear(map: Map(key, value)) -> Map(key, value)

Removes all entries. Mutates the map.

pub fn delete(
  from map: Map(key, value),
  key key: key,
) -> Map(key, value)

Removes the entry for the given key. Mutates the map.

pub fn entries(
  of map: Map(key, value),
) -> iterator.Iterator(#(key, value), Nil, Nil)
pub fn for_each(
  in map: Map(key, value),
  run callback: fn(key, value) -> a,
) -> Nil
pub fn from_list(entries: List(#(key, value))) -> Map(key, value)
pub fn get(
  from map: Map(key, value),
  key key: key,
) -> Result(value, Nil)

Returns the value associated with the given key, or an error if not found.

pub fn has(in map: Map(key, value), key key: key) -> Bool
pub fn keys(
  of map: Map(key, value),
) -> iterator.Iterator(key, Nil, Nil)
pub fn new() -> Map(key, value)
pub fn set(
  in map: Map(key, value),
  key key: key,
  value value: value,
) -> Map(key, value)

Sets the value for the given key. Mutates the map.

pub fn size(of map: Map(key, value)) -> Int
pub fn values(
  of map: Map(key, value),
) -> iterator.Iterator(value, Nil, Nil)
Search Document