class IntStr
class IntStr is Allomorph is Int { }
IntStr
is a dual value type, a subclass of both
Allomorph, hence Str, and
Int.
See Allomorph for further details.
my $int-str = <42>;
say $int-str.^name; # OUTPUT: Ā«IntStrā¤Ā»
my Int $int = $int-str; # OK!
my Str $str = $int-str; # OK!
# ā operator cares about object identity
say 42 ā <42 55 1>; # OUTPUT: Ā«Falseā¤Ā»
Methods
method new
method new(Int $i, Str $s)
The constructor requires both the Int and the Str value, when constructing one directly the values can be whatever is required:
my $f = IntStr.new(42, "forty two");
say +$f; # OUTPUT: Ā«42ā¤Ā»
say ~$f; # OUTPUT: Ā«"forty two"ā¤Ā»
method Int
method Int
Returns the integer value of the IntStr
.
method Numeric
multi method Numeric(IntStr:D: --> Int:D)
multi method Numeric(IntStr:U: --> Int:D)
The :D
variant returns the numeric portion of the invocant. The :U
variant issues
a warning about using an uninitialized value in numeric context and then returns value 0
.
method Real
multi method Real(IntStr:D: --> Int:D)
multi method Real(IntStr:U: --> Int:D)
The :D
variant returns the numeric portion of the invocant. The :U
variant issues
a warning about using an uninitialized value in numeric context and then returns value 0
.
Operators
infix ===
multi infix:<===>(IntStr:D $a, IntStr:D $b)
IntStr
Value identity operator. Returns True
if the Int
values of $a
and $b
are identical and their Str
values are also identical. Returns False
otherwise.