OxL Reference

data Map

Hash map with insertion-ordered iteration (§3.3). {k: v} literals have this type.

Example:

oxl✓ checked in CI
fn main() io {
  var ages = {"ann": 31, "bob": 27}
  ages.insert("cy", 40)
  for k in ages.keys() {
    print("{k} {ages.get(k)!}")
  }
}
Output
ann 31
bob 27
cy 40
@builtin("Map") pub(api) data Map<K, V>

Complexity. `get`, `insert`, `remove` and `contains` are O(1) on average.

Thread safety. not shared between tasks; send a copy (or a `frozen` map) to another task.

Since. 1.0.0-beta

Methods

new() -> Self
True when the map has no entries.
len() -> usize
The number of entries.
isEmpty() -> bool
Whether the map has no entries.
get(k: K) -> V?
Value for k or none.
insert(k: K, v: V)
Stores v under k, replacing the value that was there.
remove(k: K) -> V?
Removes the entry for k and returns its value, or none when there was none.
contains(k: K) -> bool
Whether the map has an entry for k.
clear()
Removes all entries.
keys() -> List<K>
The keys, in insertion order.
values() -> List<V>
The values, in the order of their keys.
iter() -> iter<(K, V)>
Lazy iterator over a snapshot of the (key, value) entries (insertion order).

Defined in: std/core/types.oxl:46

See also