Map Prototype

The map prototype ($map_proto) defines verbs that perform operations on the receiver, which will be of type MAP. All verbs are of the general form:

any map:verb(...)

Where map may be a map literal or an expression returning a map value.

keys

LIST map:keys()

Returns the keys in map.

[1 -> #1, 2 -> #2, 3 -> #3]:keys()      => {1, 2, 3}

values

LIST map:values()

Returns the values in map.

[1 -> #1, 2 -> #2, 3 -> #3]:values()      => {#1, #2, #3}

delete

MAP map:delete(key, ...)

Deletes the specified keys/values from map.

[1 -> #1, 2 -> #2, 3 -> #3]:delete(2, 3)      => [1 -> #1]

merge update

MAP map:merge(MAP other)

Returns a new map constructed from the elements in map and other. If there are duplicate keys, the keys/values in other replace the keys/values in map.

[1 -> #1, 2 -> #2, 3 -> #3]:merge([0 -> "hello", 1 -> "there"])      => [0 -> "hello", 1 -> "there", 2 -> #2, 3 -> #3]

is_empty is_blank

INT map:is_empty()

Returns true if map contains no elements.

[1 -> 2]:is_empty()     => 0
[]:is_empty()           => 1

has_key

INT map:has_key(key)

Returns true if map contains key key.

[1 -> #1, 2 -> #2, 3 -> #3]:has_key(2)      => 1
[1 -> #1, 2 -> #2, 3 -> #3]:has_key(4)      => 0

has_value

INT map:has_value(value)

Returns true if map contains value value.

[1 -> #1, 2 -> #2, 3 -> #3]:has_value(#2)      => 1
[1 -> #1, 2 -> #2, 3 -> #3]:has_value(#4)      => 0

invert

MAP map:invert()

Returns a copy of map with the keys and values swapped.

[1 -> #1, 2 -> #2, 3 -> #3]:invert()      => [#1 -> 1, #2 -> 2, #3 -> 3]

slice

MAP map:slice(key, ...)

Returns a copy of map with only the keys/values represented by the specified keys included.

[1 -> #1, 2 -> #2, 3 -> #3]:slice(2, 3)      => [2 -> #2, 3 -> #3]

to_list

LIST map:to_list()

Returns a list of lists constructed from the elements in map, using the key as the first element in the pair and the value as the second.

[1 -> 2, 3 -> 4]:to_list()     => {{1, 2}, {3, 4}}