Boolean
| Description: | A logical data type that can have only True or False values |
| Annotation: | bool |
| Literal syntax: | Either a literal true or false |
| Casts: | into bool |
| See also: | Types of Data - Booleans |
Common commands that can be used with bool
if,whilematch(in clauses where the expression matches the clause expression, or the_value which is always true)is-empty,is-not-emptyis-adminis-terminal
The following commands take a closure (or a row condition) as their main argument. The return value from the closure must be a boolean:
whereany,all,skip until,skip while,take until,take while
Common operators that can be used with bool
==,!=,<,<=,>,>=and,or,xor,notin- Regex comparison operators:
=~,!~<regex> - String comparison operators:
ends-with,starts-with
Short-circuit evaluation
and and or short-circuit: the right-hand operand is only evaluated when the left-hand operand doesn't already decide the result. With and, the right-hand side is skipped when the left-hand side is false; with or, it is skipped when the left-hand side is true.
def check [] { print "check was called"; true }
false and (check)
# => false
true or (check)
# => true
true and (check)
# => check was called
# => trueThis means a condition can guard an expression that would otherwise fail:
let text = ""
($text != "") and (($text | split chars | last) == "%")
# => false