Dictionary Prototypes
Dictionary values expose key/value helpers.
let user = { "name": "Martin", "age": 19}
println(user.keys())println(user.values())Literal calls
Section titled “Literal calls”Store a literal in a variable before calling its methods. Direct prototype calls on literals are limited by the current parser.
Methods
Section titled “Methods”| Method | Returns | Description |
|---|---|---|
keys() | []K | Returns all dictionary keys. |
values() | []V | Returns all dictionary values. |
remove(key: K) | void | Removes a key from the dictionary. |
Indexed Access
Section titled “Indexed Access”Dictionaries implement internal __get__ and __set__, which power indexed access.
let user = { "name": "Martin"}
println(user["name"])
user["role"] = "admin"
println(user["role"])Keys and Values
Section titled “Keys and Values”let config = { "host": "localhost", "port": 3000}
println(config.keys())println(config.values())Removing Keys
Section titled “Removing Keys”let config = { "host": "localhost", "port": 3000}
config.remove("host")
println(config.keys())Missing Keys
Section titled “Missing Keys”If a key does not exist, direct access can throw an error.
let config = { "port": 3000}
catch err { println(config["host"])}
if !isNil(err) { println(err.message)}