Logical Boolean
<False True>
An enum for Boolean true/false decisions.
method ACCEPTS(Bool: --> Bool)
Used for smartmatch comparison. When the right side is True
returns always True
, when the right side of the match is False
returns always False
. In particular, ACCEPTS
returns always the instance on which it is invoked, that is the right side of a smartmatch. As an example:
my = Bool.new( True );# when True on the right side returns# always TrueTrue ~~ ; # TrueFalse ~~ ; # True= Bool.new( False );# when False on the right side# returns always FalseFalse ~~ ; # FalseTrue ~~ ; # False
method succ(--> Bool)
Returns True
.
say True.succ; # OUTPUT: «True»say False.succ; # OUTPUT: «True»
succ
is short for "successor"; it returns the next enum value. Bool is a special enum with only two values, False
and True
. When sorted, False
comes first, so True
is its successor. And since True
is the "highest" Bool enum value, its own successor is also True
.
method pred(--> Bool)
Returns False
.
say True.pred; # OUTPUT: «False»say False.pred; # OUTPUT: «False»
pred
is short for "predecessor"; it returns the previous enum value. Bool is a special enum with only two values, False
and True
. When sorted, False
comes first, so False
is the predecessor to True
. And since False
is the "lowest" Bool enum value, its own predecessor is also False
.
method enums(--> Hash)
Returns a Hash of enum-pairs. Works on both the Bool
type and any key.
say Bool.enums; # OUTPUT: «{False => 0, True => 1}»say False.enums; # OUTPUT: «{False => 0, True => 1}»
multi method pick(Bool --> Bool)multi method pick(Bool --> Seq)
Returns True
or False
if called without any argument. Otherwise returns $count
elements chosen at random (without repetition) from the enum
. If *
is passed as $count
, or $count
is greater than or equal to two, then both elements are returned in random order.
say Bool.pick; # OUTPUT: «True»say Bool.pick(1); # OUTPUT: «(False)»say Bool.pick(*); # OUTPUT: «(False True)»
multi method roll(Bool --> Bool)multi method roll(Bool --> Seq)
Returns True
or False
if called without any argument. Otherwise returns $count
elements chosen at random. Note that each random choice from the enum
is made independently, like a separate coin toss where each side of the coin represents one of the two values of the enum
. If *
is passed as $count
an infinite Seq of Bool
s is returned.
say Bool.roll; # OUTPUT: «True»say Bool.roll(3); # OUTPUT: «(True False False)»say Bool.roll(*); # OUTPUT: «(...)»
multi method Int(Bool --> Int)
Returns the value part of the enum
pair.
say False.Int; # OUTPUT: «0»say True.Int; # OUTPUT: «1»
multi method Numeric(Bool --> Int)
Returns the value part of the enum
pair.
say False.Numeric; # OUTPUT: «0»say True.Numeric; # OUTPUT: «1»
multi sub prefix:<?>(Mu --> Bool)
Coerces its argument to Bool
.
multi sub prefix:<so>(Mu --> Bool)
Coerces its argument to Bool
, has looser precedence than prefix:<?>
.