In Quarkdown, a dictionary is a collection of key-value pairs without duplicate keys. Keys are always strings, while values can be any type.
The dictionary syntax resembles YAML and uses Markdown lists:
- key1: value1
- key2: value2
- key3: value3Since this syntax overlaps with Iterable syntax, you can wrap the dictionary declaration in a .dictionary function to remove ambiguity when both types are accepted.
.foreach accepts both iterables and dictionaries, so we explicitly create a dictionary to iterate over key-value pairs, and destructure them into separate variables.
.var {mydictionary}
.dictionary
- key1: value1
- key2: value2
- key3: value3
.foreach {.mydictionary}
key value:
**.key**: .valuekey1: value1
key2: value2
key3: value3
You can nest dictionaries when the function supports it, such as .localization:
- English:
- greeting: Hello
- food: Fish and chips
- Italian:
- greeting: Ciao
- food: PastaTrailing colons before nested dictionaries are optional:
- English
- greeting: Hello
- food: Fish and chips
- Italian
- greeting: Ciao
- food: PastaYou can pass a dictionary to any function that accepts an iterable, where it is treated as an iterable of pairs.
For a complete list of dictionary operations, see the Dictionary documentation in the standard library.