routine Bool
1 | class List |
1.1 | (List) method Bool |
2 | class Capture |
2.1 | (Capture) method Bool |
3 | class Promise |
3.1 | (Promise) method Bool |
4 | role Baggy |
4.1 | (Baggy) method Bool |
5 | class Junction |
5.1 | (Junction) method Bool |
6 | role Setty |
6.1 | (Setty) method Bool |
7 | class Mu |
7.1 | (Mu) routine Bool |
8 | class Str |
8.1 | (Str) method Bool |
9 | class ComplexStr |
9.1 | (ComplexStr) method Bool |
10 | class Regex |
10.1 | (Regex) method Bool |
11 | class Numeric |
11.1 | (Numeric) method Bool |
12 | class IntStr |
12.1 | (IntStr) method Bool |
13 | class NumStr |
13.1 | (NumStr) method Bool |
14 | class StrDistance |
14.1 | (StrDistance) method Bool |
15 | class RatStr |
15.1 | (RatStr) method Bool |
16 | class Match |
16.1 | (Match) method Bool |
17 | role Rational |
17.1 | (Rational) method Bool |
18 | role Blob |
18.1 | (Blob) method Bool |
19 | class Failure |
19.1 | (Failure) method Bool |
20 | class Map |
20.1 | (Map) method Bool |
Documentation for routine Bool
assembled from the following types:
class List
From List
(List) method Bool
Defined as:
method Bool(List: --> Bool)
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»
class Capture
From Capture
(Capture) method Bool
Defined as:
method Bool(Capture: --> Bool)
Returns True
if the Capture contains at least one named or one positional argument.
say \(1,2,3, apples => 2).Bool; # OUTPUT: «True»say \().Bool; # OUTPUT: «False»
class Promise
From Promise
(Promise) method Bool
multi method Bool(Promise:)
Returns True
for a kept or broken promise, and False
for one in state Planned
.
role Baggy
From Baggy
(Baggy) method Bool
Defined as:
method Bool(Baggy: --> Bool)
Returns True
if the invocant contains at least one element.
my = ('eggs' => 1).BagHash;say .Bool; # OUTPUT: «True (since we have one element)»<eggs> = 0; # weight == 0 will lead to element removalsay .Bool; # OUTPUT: «False»
class Junction
From Junction
(Junction) method Bool
Defined as:
multi method Bool(Junction:)
Collapses the Junction
and returns a single Boolean value according to the type and the values it holds. Every element is transformed to Bool
.
my = Junction.new( "one", 1..6 );say .Bool; # OUTPUT: «False»
All elements in this case are converted to True
, so it's false to assert that only one of them is.
my = Junction.new( "one", <0 1> );say .Bool; # OUTPUT: «True»
Just one of them is truish in this case, 1
, so the coercion to Bool
returns True
.
role Setty
From Setty
(Setty) method Bool
Defined as:
multi method Bool(Setty: --> Bool)
Returns True
if the invocant contains at least one element.
my = Set.new(1, 2, 3);say .Bool; # OUTPUT: «True»my = ∩ Set.new(4, 5); # set intersection operatorsay .Bool; # OUTPUT: «False»
class Mu
From Mu
(Mu) routine Bool
multi sub Bool(Mu --> Bool)multi method Bool( --> Bool)
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 Mu.new.Bool; # OUTPUT: «True»say [1, 2, 3].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 Str
From Str
(Str) method Bool
Defined as:
method Bool(Str: --> Bool)
Returns False
if the string is empty, True
otherwise.
class ComplexStr
From ComplexStr
(ComplexStr) method Bool
Defined as:
multi method Bool(ComplexStr: --> Bool)
This method may be provided by the parent classes and not implemented in ComplexStr directly.
Returns False
if the invocant is numerically ±0±0i
, otherwise returns True
. String portion is not considered.
class Regex
From Regex
(Regex) method Bool
multi method Bool(Regex: --> Bool)
Matches against the caller's $_ variable, and returns True
for a match or False
for no match.
class Numeric
From Numeric
(Numeric) method Bool
multi method Bool(Numeric:)
Returns False
if the number is equivalent to zero, and True
otherwise.
class IntStr
From IntStr
(IntStr) method Bool
Defined as:
multi method Bool(IntStr: --> Bool)
This method may be provided by the parent classes and not implemented in IntStr directly.
Returns False
if the invocant is numerically 0
, otherwise returns True
. String portion is not considered.
class NumStr
From NumStr
(NumStr) method Bool
Defined as:
multi method Bool(NumStr: --> Bool)
This method may be provided by the parent classes and not implemented in NumStr directly.
Returns False
if the invocant is numerically ±0e0
, otherwise returns True
. String portion is not considered.
class StrDistance
From StrDistance
(StrDistance) method Bool
Returns True
if before
is different from after
.
class RatStr
From RatStr
(RatStr) method Bool
Defined as:
multi method Bool(RatStr: --> Bool)
This method may be provided by the parent classes and not implemented in RatStr directly.
Returns False
if the numerator of the numeric portion is 0
, otherwise returns True
. This applies for < 0/0 >
zero-denominator RatStr as well, despite ?< 0/0 >.Num
being True
. String portion is not considered.
class Match
From Match
(Match) method Bool
Defined as:
method Bool(Capture: --> Bool)
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»
role Rational
From Rational
(Rational) method Bool
Defined as:
multi method Bool(Rational: --> Bool)
Returns False
if numerator is 0
, otherwise returns True
. This applies for <0/0>
zero-denominator Rational as well, despite ?<0/0>.Num
being True
.
role Blob
From Blob
(Blob) method Bool
Defined as:
multi method Bool(Blob:)
Returns False
if and only if the buffer is empty.
my = Blob.new();say .Bool; # OUTPUT: «False»= Blob.new([1, 2, 3]);say .Bool; # OUTPUT: «True»
class Failure
From Failure
(Failure) method Bool
Defined as:
multi method Bool(Failure: --> Bool)
Returns False
, and marks the failure as handled.
sub f() ; my = f; say .handled; .Bool; say .handled;# OUTPUT: «False# True»
class Map
From Map
(Map) method Bool
Defined as:
method Bool(Map: --> Bool)
Returns True
if the invocant contains at least one key/value pair.
my = Map.new('a' => 2, 'b' => 17);say .Bool; # OUTPUT: «True»