Skip to content

Commit eef9417

Browse files
committed
provide some examples in the documentation
1 parent eb6adf7 commit eef9417

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

docs/src/ref/choice_maps.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,42 @@ for sub-choicemaps. Leaf nodes have type:
1414
ValueChoiceMap
1515
```
1616

17+
### Example Usage Overview
18+
19+
Choicemaps store values nested in a tree where each node posesses an address for each subtree.
20+
A leaf-node choicemap simply contains a value, and has it's value looked up via:
21+
```julia
22+
value = choicemap[]
23+
```
24+
If a choicemap has a value choicemap at address `:a`, it is looked up via:
25+
```julia
26+
value = choicemap[:a]
27+
```
28+
And a choicemap may also have a non-value choicemap stored at a value. For instance,
29+
if a choicemap has another choicemap stored at address `:a`, and this internal choicemap
30+
has a valuechoicemap stored at address `:b` and another at `:c`, we could perform the following lookups:
31+
```julia
32+
value1 = choicemap[:a => :b]
33+
value2 = choicemap[:a => :c]
34+
```
35+
Nesting can be arbitrarily deep, and the keys can be arbitrary values; for instance
36+
choicemaps can be constructed with values at the following nested addresses:
37+
```julia
38+
value = choicemap[:a => :b => :c => 4 => 1.63 => :e]
39+
value = choicemap[:a => :b => :a => 2 => "alphabet" => :e]
40+
```
41+
To get a sub-choicemap, use `get_submap`:
42+
```julia
43+
value1 = choicemap[:a => :b]
44+
submap = get_submap(choicemap, :a)
45+
value1 == submap[:b] # is true
46+
47+
value_submap = get_submap(choicemap, :a => :b)
48+
value_submap[] == value1 # is true
49+
```
50+
51+
### Interface
52+
1753
Choice maps provide the following methods:
1854
```@docs
1955
get_submap
@@ -58,7 +94,7 @@ set_value!
5894
set_submap!
5995
```
6096

61-
## Implementing custom choicemap types
97+
### Implementing custom choicemap types
6298

6399
To implement a custom choicemap, one must implement
64100
`get_submap` and `get_submaps_shallow`.

0 commit comments

Comments
 (0)