compare.Default
Returns the second argument if set, else the first argument.
- Syntax
- compare.Default DEFAULT INPUT
- Returns
- any
- Alias
- default
Usage
The compare.Default function returns the second argument if set, else the first argument.
When the second argument is the boolean false value, the compare.Default function returns false. All other falsy values are considered unset.
The falsy values are false, 0, any nil pointer or interface value, any array, slice, map, or string of length zero, and zero time.Time values.
Everything else is truthy.
To set a default value based on truthiness, use the or operator instead.
Examples
When the second argument is set:
{{ 1 | compare.Default 42 }} → 1
{{ "foo" | compare.Default 42 }} → foo
{{ dict "k" "v" | compare.Default 42 }} → map[k:v]
{{ slice "a" "b" | compare.Default 42 }} → [a b]
{{ true | compare.Default 42 }} → true
<!-- As noted above, the boolean "false" is considered set -->
{{ false | compare.Default 42 }} → falseWhen the second argument is not set:
{{ 0 | compare.Default 42 }} → 42
{{ "" | compare.Default 42 }} → 42
{{ dict | compare.Default 42 }} → 42
{{ slice | compare.Default 42 }} → 42