githubEdit

Map Library (Map)

Linked with the "map" type.

Maps are ordered by keys.

Example Usage

#[main]
fn main() {
    const a = {1: 'hi'};
    assert_eq(a.len(), 1);
    assert_eq(Map.len(a), 1);
}

Map.any(this: map) -> bool

Does this map contain any key-value pairs?

const map = map();
assert_not(map.any());

Map.append(this: map, other: map) -> void

Append the items of another map onto this map.

const map = {"a": 1};
map.append({"b": 2});
assert_eq(map, {"a": 1, "b": 2});

Map.at(this: map, index: int) -> (unknown, unknown)

The key-value pair at the given index in this sorted map.

Map.clear(this: map) -> void

Clear this map of all items.

Map.contains(this: map, key: unknown) -> bool

Returns true if this map contains a key that equals the given value.

Map.empty(this: map) -> bool

Is this map empty?

Map.first(this: map) -> (unknown, unknown)

Return the first key-value pair in this ordered map, or null if the map is empty. Optionally return the value as a reference with the '&' operator.

Map.get(this: map, key: unknown) -> unknown

Return a value for the given key in this map, optionally by reference.

Map.insert(this: map, key: unknown, value: unknown) -> unknown

Insert a key-value pair into this map, returning the old value if the key was already present, or null otherwise.

Map.keys(this: map) -> set

A set of this map's keys.

Map.last(this: map) -> (unknown, unknown)

Return the last key-value pair in this ordered map, or null if the map is empty. Optionally return the value as a reference with the '&' operator.

Map.len(this: map) -> int

The number of key-value pairs in this map.

Map.pop_first(this: map) -> (unknown, unknown)

Remove the smallest key-value pair from this map and return it.

Map.pop_last(this: map) -> (unknown, unknown)

Remove the largest key-value pair from this map and return it.

Map.remove(this: map, key: unknown) -> unknown

Remove the value with the given key and return it, or null if the key isn't present.

Map.values(this: map) -> list

A list of this map's values.

Last updated