A map is an ordered key/value object.
Create a map with `map(…)`.
lookup = map(); lookup = map('x', 10, 'y', 20);
Keys are converted to strings.
Creates an empty map.
| Item | Description |
|---|---|
| Syntax | `map()` |
| Arguments | none |
| Returns | map object |
Example:
lookup = map(); lookup.empty(); // true
Creates a map initialized with key/value pairs.
| Argument | Type | Description |
|---|---|---|
| `key` | any | Key converted to string. |
| `value` | any | Value stored for the key. |
| `…` | any | Additional key/value pairs. |
Returns: map object.
The number of arguments must be even.
Example:
lookup = map('x', 10, 'y', 20); lookup.get('x'); // 10
Map keys can be read as properties when the key is a valid property name.
lookup = map('x', 10); lookup.x; // 10
Property access is read-only. Use `set(key, value)` to change a map entry.
lookup.set('x', 20);
Returns a display string for the object.
| Item | Description |
|---|---|
| Syntax | `value.to_string()` |
| Arguments | none |
| Returns | string |
Example:
text = value.to_string();
Returns a new map object with the same key/value pairs.
| Item | Description |
|---|---|
| Syntax | `map.clone()` |
| Arguments | none |
| Returns | map object |
Example:
lookup = map('x', 10); copy = lookup.clone();
Returns the number of key/value pairs in the map.
| Item | Description |
|---|---|
| Syntax | `map.size()` |
| Arguments | none |
| Returns | number |
Example:
map('x', 10, 'y', 20).size(); // 2
Alias for `size()`.
| Item | Description |
|---|---|
| Syntax | `map.count()` |
| Arguments | none |
| Returns | number |
Example:
map('x', 10).count(); // 1
Returns true when the map has no entries.
| Item | Description |
|---|---|
| Syntax | `map.empty()` |
| Arguments | none |
| Returns | boolean-style number |
Example:
lookup = map(); lookup.empty(); // true
Removes all entries from the map.
| Item | Description |
|---|---|
| Syntax | `map.clear()` |
| Arguments | none |
| Returns | boolean-style number |
Example:
lookup = map('x', 10); lookup.clear(); lookup.size(); // 0
Checks whether a key exists.
| Argument | Type | Description |
|---|---|---|
| `key` | any | Key converted to string. |
Returns: boolean-style number.
Example:
lookup = map('x', 10); lookup.has('x'); // true lookup.has('z'); // false
Returns the value for a key.
| Argument | Type | Description |
|---|---|---|
| `key` | any | Key converted to string. |
Returns: stored value, or `none()` when the key does not exist.
Example:
lookup = map('x', 10); lookup.get('x'); // 10 lookup.get('z').is_none(); // true
Stores a value for a key.
| Argument | Type | Description |
|---|---|---|
| `key` | any | Key converted to string. |
| `value` | any | Value to store. |
Returns: boolean-style number.
Example:
lookup = map(); lookup.set('x', 10); lookup.get('x'); // 10
Removes a key/value pair.
| Argument | Type | Description |
|---|---|---|
| `key` | any | Key converted to string. |
Returns: true if a value was removed, false when the key did not exist.
Example:
lookup = map('x', 10); lookup.remove('x'); // true lookup.remove('x'); // false
Returns an array of keys in insertion order.
| Item | Description |
|---|---|
| Syntax | `map.keys()` |
| Arguments | none |
| Returns | array object |
Example:
lookup = map('x', 10, 'y', 20); lookup.keys().to_string(); // ["x", "y"]