While it is always possible to use mixins or method overrides to modify the Bool coercions, by default what values are considered to be truthy and what values are considered to be falsy?
Note: this question was asked previously, but unfortunately it is so old its content is completely out of date and useless is modern Raku.
There are no truthy values, as each type decides for itself via a .Bool
method that is called in boolean contexts. For built-in types, the following return False
when their .Bool
method is called.
0
(except Rat
of x/0
where x≠0
)Failure
Promise
prior to being kept/broken.StrDistance
whose before/after is the same.Junction
, when you expect it to.Otherwise, any defined value by default returns True
when its .Bool
method is called. This includes the Str
'0'
, NaN
, and zero-length range (0^..^0
) that in other languages might not be truthy.
This answer is intended as a quick reference. See this answer for a more detailed discussion.