Skip to content

Map<K, V>

A key-value store mapping keys of type K to values of type V.

Keys must be hashable: int, float, bool, string, color, or enum. Create with Map.new() or a map literal {"key": value}.

Kind: object

Static Methods

new

navi
Map.new(): const Map<K, V>

Creates a new empty map of the specified key and value types.

Returns: const Map<K, V>

Methods

clear

navi
Map.clear(id: Map<K, V>)

Clears all entries from the given map.

Parameters

NameTypeDefaultDescription
idMap<K, V>the map to clear.

contains

navi
Map.contains(id: Map<K, V>, key: K): bool

Checks if the specified key exists in the given map.

It returns true if the key is found, otherwise false.

Parameters

NameTypeDefaultDescription
idMap<K, V>the map to search in.
keyKThe key to check for existence.

Returns: bool


copy

navi
Map.copy(id: Map<K, V>): Map<K, V>

Creates a copy of the given map and returns the new id.

Parameters

NameTypeDefaultDescription
idMap<K, V>the map to copy.

Returns: Map<K, V>


get

navi
Map.get(id: Map<K, V>, key: K): V

Retrieves the value associated with the specified key in the given id, or returns na if the key does not exist.

Parameters

NameTypeDefaultDescription
idMap<K, V>the map to retrieve the value from.
keyKThe key to look up in the map.

Returns: V — The value associated with key, or na if the key does not exist.


keys

navi
Map.keys(id: Map<K, V>): Array<K>

Returns an array containing all the keys present in the given id.

Parameters

NameTypeDefaultDescription
idMap<K, V>the map to get the keys from.

Returns: Array<K>


put

navi
Map.put(id: Map<K, V>, key: K, value: V): V

Inserts or updates the value associated with the specified key in the given map.

It returns the previous value if the key existed, or na if it is a new entry.

Parameters

NameTypeDefaultDescription
idMap<K, V>the map to insert or update a value in.
keyKThe key to associate with the value.
valueVThe value to insert or update.

Returns: V — The previous value associated with key, or na if the key was not previously present.


put_all

navi
Map.put_all(id: Map<K, V>, id2: Map<K, V>)

Copies all key-value pairs from the source map to the destination id.

Existing keys in the destination id will be updated with values from the source id.

Parameters

NameTypeDefaultDescription
idMap<K, V>The destination id to copy values into.
id2Map<K, V>The source id to copy values from.

remove

navi
Map.remove(id: Map<K, V>, key: K): V

Removes the entry associated with the specified key from the given map.

It returns the removed value if the key existed, or na if the key was not found.

Parameters

NameTypeDefaultDescription
idMap<K, V>the map to remove a value from.
keyKThe key of the entry to remove.

Returns: V — The removed value, or na if the key was not found.


size

navi
Map.size(id: Map<K, V>): int

Returns the number of key-value pairs currently stored in the given map.

Parameters

NameTypeDefaultDescription
idMap<K, V>the map to get the size of.

Returns: int


values

navi
Map.values(id: Map<K, V>): Array<V>

Returns an array containing all the values present in the given id.

Parameters

NameTypeDefaultDescription
idMap<K, V>the map to get the values from.

Returns: Array<V>

Released under the MIT License.