Marcel van Lohuizen | 75cb003 | 2019-01-11 12:10:48 +0100 | [diff] [blame] | 1 | [TOC](Readme.md) [Prev](fieldcomp.md) [Next](coalesce.md) |
| 2 | |
Marcel van Lohuizen | af0932f | 2019-01-11 13:03:56 +0100 | [diff] [blame] | 3 | _Expressions_ |
| 4 | |
Marcel van Lohuizen | 75cb003 | 2019-01-11 12:10:48 +0100 | [diff] [blame] | 5 | # Conditional Fields |
| 6 | |
| 7 | Field comprehensions can also be used to |
| 8 | add a single field conditionally. |
| 9 | |
| 10 | Converting the resulting configuration to JSON results in an error |
| 11 | as `justification` is required yet no concrete value is given. |
| 12 | |
| 13 | |
| 14 | <!-- CUE editor --> |
| 15 | ``` |
| 16 | price: float |
| 17 | |
| 18 | // Require a justification if price is too high |
| 19 | justification: string if price > 100 |
| 20 | |
| 21 | price: 200 |
| 22 | ``` |
| 23 | |
| 24 | <!-- result --> |
| 25 | ``` |
| 26 | price: 200 |
| 27 | justification: string |
| 28 | ``` |