Skip to content

Commit

Permalink
Add simple destructuring assignment example
Browse files Browse the repository at this point in the history
Signed-off-by: Anders Eknert <anders@eknert.com>
  • Loading branch information
anderseknert committed Dec 2, 2021
1 parent 381a204 commit 37d2025
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions docs/content/policy-language.md
Original file line number Diff line number Diff line change
Expand Up @@ -1671,6 +1671,21 @@ q {
```live:eg/assignment2:output:expect_assigned_above,expect_referenced_above
```

A simple form of destructuring can be used to unpack values from arrays and assign them to variables:

```live:eg/assignment3:module:read_only
address := ["3 Abbey Road", "NW8 9AY", "London", "England"]
in_london {
[_, _, city, country] := address
city == "London"
country == "England"
}
```
```live:eg/assignment3:output
```


#### Comparison `==`

Comparison checks if two values are equal within a rule. If the left or right hand side contains a variable that has not been assigned a value, the compiler throws an error.
Expand Down

0 comments on commit 37d2025

Please sign in to comment.