gossamer/map
JavaScript Map bindings for interop with APIs that produce or
consume a Map. Treated as a transit type: bridge to
gleam/dict.Dict
via to_dict and operate on the canonical Gleam
surface for transformations, then from_dict back
when handing off to JavaScript. The non-mutating reads
(size, get, has,
keys, values, entries) stay
for one-shot interop without round-tripping through Dict.
Types
A JavaScript Map, holding key-value pairs and preserving insertion
order. Supports any key type (unlike plain objects).
For most Gleam use cases, prefer gleam/dict.Dict. This binding
exists for interop with JavaScript code that expects a Map; bridge
with to_dict / from_dict and operate on the Dict surface for
transformations.
Object keys (records, lists, tuples) are matched by JavaScript
reference identity, not by Gleam 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 entries(
map: Map(key, value),
) -> yielder.Yielder(#(key, value))
Returns the #(key, value) pairs of the Map in insertion order.
pub fn from_dict(dict: dict.Dict(key, value)) -> Map(key, value)
Creates a Map from a Dict. Iteration order follows the Dict’s
to_list order.
pub fn from_list(entries: List(#(key, value))) -> Map(key, value)
Creates a Map from a list of key-value pairs. Later pairs override
earlier ones for the same key.
pub fn get(
from map: Map(key, value),
key key: key,
) -> Result(value, Nil)
Returns the value associated with the given key, or Error(Nil) if
the key is absent.
pub fn has(in map: Map(key, value), key key: key) -> Bool
Returns whether the Map contains the given key.
pub fn keys(map: Map(key, value)) -> yielder.Yielder(key)
Returns the keys of the Map in insertion order.
pub fn to_dict(map: Map(key, value)) -> dict.Dict(key, value)
Converts the Map to a Dict. Iteration order is preserved as
Dict insertion order.
pub fn values(map: Map(key, value)) -> yielder.Yielder(value)
Returns the values of the Map in insertion order.