Map Functions

CSL supports the following functions for the manipulation of maps (ordered or unordered collections of key-value pairs):

 

asMap(key-1, value-1, ... key-n, value-n)

Returns a new, unordered map containing the pair <key-i, value-i>, for every i between 1 and n, inclusive. There must be an even number of arguments. The arguments must alternate between key and value, and must start with a key and end with a value. If there are no arguments (as in asMap()), an empty map is returned. The map is implemented as a Java HashMap.

 

asOrderedMap(key-1, value-1, ... key-n, value-n)

Returns a new, ordered map containing the pair <key-i, value-i>, for every i between 1 and n, inclusive. There must be an even number of arguments. The arguments must alternate between key and value, and must start with a key and end with a value. If there are no arguments (as in asMap()), an empty map is returned. The map is implemented as a Java TreeMap.

 

mapGet(map, key)

Returns the value associated with the given key in the map. For Integer and String keys, you can also use the square-bracket notation, as in myMap[3] and myMap['blue']. Calls to mapGet work for any key type.

 

mapPut(map, key, value)

Adds a new key-value pair to an existing map.