default
To set a simple default value, use default
:
default "foo" .Bar
In the above, if .Bar
evaluates to a non-empty value, it will be used. But if
it is empty, foo
will be returned instead.
The definition of "empty" depends on type:
- Numeric: 0
- String: ""
- Lists:
[]
- Dicts:
{}
- Boolean:
false
- And always
nil
(aka null)
For structs, there is no definition of empty, so a struct will never return the default.
Back to top