Documentation for routine Bool

Documentation for routine Bool, assembled from the following types:

class Mu

From Mu

(Mu) routine Bool

multi sub    Bool(Mu --> Bool:D)
multi method Bool(   --> Bool:D)

Returns False on the type object, and True otherwise.

Many built-in types override this to be False for empty collections, the empty string or numerical zeros

say Mu.Bool;                    # OUTPUT: «False␤» 
say;                # OUTPUT: «True␤» 
say [123].Bool;             # OUTPUT: «True␤» 
say [].Bool;                    # OUTPUT: «False␤» 
say { 'hash' => 'full' }.Bool;  # OUTPUT: «True␤» 
say {}.Bool;                    # OUTPUT: «False␤» 
say "".Bool;                    # OUTPUT: «False␤» 
say 0.Bool;                     # OUTPUT: «False␤» 
say 1.Bool;                     # OUTPUT: «True␤» 
say "0".Bool;                   # OUTPUT: «True␤» 

class List

From List

(List) method Bool

Defined as:

method Bool(List:D: --> Bool:D)

Returns True if the list has at least one element, and False for the empty list.

say ().Bool;  # OUTPUT: «False␤» 
say (1).Bool# OUTPUT: «True␤» 

role Baggy

From Baggy

(Baggy) method Bool

Defined as:

method Bool(Baggy:D: --> Bool:D)

Returns True if the invocant contains at least one element.

my $breakfast = ('eggs' => 1).BagHash;
say $breakfast.Bool;                              # OUTPUT: «True   (since we have one element)␤» 
$breakfast<eggs> = 0;                             # weight == 0 will lead to element removal 
say $breakfast.Bool;                              # OUTPUT: «False␤» 

role Blob

From Blob

(Blob) method Bool

Defined as:

multi method Bool(Blob:D:)

Returns False if and only if the buffer is empty.

my $blob =;
say $blob.Bool# OUTPUT: «False␤» 
$blob =[123]);
say $blob.Bool# OUTPUT: «True␤» 

role Numeric

From Numeric

(Numeric) method Bool

multi method Bool(Numeric:D:)

Returns False if the number is equivalent to zero, and True otherwise.

class Capture

From Capture

(Capture) method Bool

Defined as:

method Bool(Capture:D: --> Bool:D)

Returns True if the Capture contains at least one named or one positional argument.

say \(1,2,3apples => 2).Bool;                   # OUTPUT: «True␤» 
say \().Bool;                                     # OUTPUT: «False␤» 

class Str

From Str

(Str) method Bool

Defined as:

method Bool(Str:D: --> Bool:D)

Returns False if the string is empty, True otherwise.

class Failure

From Failure

(Failure) method Bool

Defined as:

multi method Bool(Failure:D: --> Bool:D)

Returns False, and marks the failure as handled.

sub f() { fail }my $v = fsay $v.handled$v.Boolsay $v.handled;
# OUTPUT: «False␤ 
# True␤» 

class Map

From Map

(Map) method Bool

Defined as:

method Bool(Map:D: --> Bool:D)

Returns True if the invocant contains at least one key/value pair.

my $m ='a' => 2'b' => 17);
say $m.Bool;                                      # OUTPUT: «True␤» 

class Match

From Match

(Match) method Bool

Defined as:

method Bool(Capture:D: --> Bool:D)

Returns True on successful and False on unsuccessful matches. Please note that any zero-width match can also be successful.

say 'abc' ~~ /^/;                   # OUTPUT: «「」␤» 
say $/.from' ',  $/.to' '?$/# OUTPUT: «0 0 True␤» 

class Promise

From Promise

(Promise) method Bool

multi method Bool(Promise:D:)

Returns True for a kept or broken promise, and False for one in state Planned.

class Regex

From Regex

(Regex) method Bool

multi method Bool(Regex:D: --> Bool:D)

Matches against the caller's $_ variable, and returns True for a match or False for no match.

role Setty

From Setty

(Setty) method Bool

Defined as:

multi method Bool(Setty:D: --> Bool:D)

Returns True if the invocant contains at least one element.

my $s1 =;
say $s1.Bool;                                     # OUTPUT: «True␤» 
my $s2 = $s1;                     # set intersection operator 
say $s2.Bool;                                     # OUTPUT: «False␤»