What are the truthy and falsy values in 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)
  • Empty list/collection types (List, Array, Hash, Map, Set, Bag, etc)
  • Empty string
  • Failure
  • Promise prior to being kept/broken.
  • StrDistance whose before/after is the same.
  • Junction, when you expect it to.
  • Type objects
  • Nil (technically type object)
  • Any undefined value (technically type objects)

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.


TL;DR This answer is an exhaustive summary based on the relevant doc.1

  • The base case2 is True for a defined object (an instance) and False for an undefined one (a type object).

  • Numerically 0 values or 0/0 are False. (But a Rational with a non-zero numerator eg 1/0 is True and (0/0).Num (which evaluates to NaN) is True.)

  • An empty collection (List, Hash, Set, Buf, etc) is False.

  • An empty string (eg literal "") is False. (NB. "0", "0.0" etc. are True.)

  • A defined Failure is False.

  • A defined Promise is False until its status becomes Kept/Broken.

  • A defined StrDistance is False if the string transformation it represents had no effect on the string being transformed.

  • A defined Junction is True or False depending on the junction's type and the True/False values of its elements.

Footnotes

1 I wrote the first bullet item based on just knowing it to be true because it's fundamental to P6 and also confirming it by checking the compiler's code.2 The other bullet points summarize the content at the time of writing this answer of the .Bool doc page at which point it listed 20 types. If the latter page was incomplete then this answer is incomplete.

2 The base case can be seen by looking at the Rakudo implementation code, in particular the core's Mu.pm6. See my answer to a similarish SO for relevant code links.