routine Int
1 | class List |
1.1 | (List) method Int |
2 | enum Bool |
2.1 | (Bool) routine Int |
3 | role Enumeration |
3.1 | (Enumeration) method Int |
4 | class Str |
4.1 | (Str) method Int |
5 | class Numeric |
5.1 | (Numeric) method Int |
6 | class IntStr |
6.1 | (IntStr) method Int |
7 | class StrDistance |
7.1 | (StrDistance) method Int |
8 | class Match |
8.1 | (Match) method Int |
9 | role Rational |
9.1 | (Rational) method Int |
10 | class Map |
10.1 | (Map) method Int |
11 | class IO::Path |
11.1 | (IO::Path) method Int |
Documentation for routine Int
assembled from the following types:
class List
From List
(List) method Int
Defined as:
method Int(List: --> Int)
Returns the number of elements in the list (same as .elems
).
say (1,2,3,4,5).Int; # OUTPUT: «5»
enum Bool
From Bool
(Bool) routine Int
multi method Int(Bool --> Int)
Returns the value part of the enum
pair.
say False.Int; # OUTPUT: «0»say True.Int; # OUTPUT: «1»
role Enumeration
From Enumeration
(Enumeration) method Int
Defined as:
multi method Int(::?CLASS:)
Takes a value of an enum and returns it after coercion to Int
:
( cool => '42', almost-pi => '3.14', sqrt-n-one => 'i' );say cool.Int; # OUTPUT: «42»say almost-pi.Int; # OUTPUT: «3»try say sqrt-n-one.Int;say $!.message if $!; # OUTPUT: «Cannot convert 0+1i to Int: imaginary part not zero»
Note that if the value cannot be coerced to Int
, an exception will be thrown.
class Str
From Str
(Str) method Int
Defined as:
method Int(Str: --> Int)
Coerces the string to Int, using the same rules as Str.Numeric
.
class Numeric
From Numeric
(Numeric) method Int
method Int(Numeric: --> Int)
If this Numeric
is equivalent to a Real
, return the equivalent of calling truncate
on that Real
to get an Int
. Fail with X::Numeric::Real
otherwise.
class IntStr
From IntStr
(IntStr) method Int
method Int
Returns the integer value of the IntStr
.
class StrDistance
From StrDistance
(StrDistance) method Int
Defined as:
multi method Int(StrDistance:)
Returns the distance between the string before and after the transformation.
class Match
From Match
(Match) method Int
Defined as:
method Int(Match: --> Int)
Tries to convert stringified result of the matched text into Int.
say ('12345' ~~ /234/).Int; # OUTPUT: «234»say ('12345' ~~ /234/).Int.^name; # OUTPUT: «Int»# the next line produces a warning about using Nil (result of a no match) in numeric contextsay ('one-two' ~~ /234/).Int; # OUTPUT: «0» # because Nil.Int returns 0
role Rational
From Rational
(Rational) method Int
Defined as:
method Int(Rational: --> Int)
Coerces the invocant to Int by truncating non-whole portion of the represented number, if any. If the denominator is zero, will fail with X::Numeric::DivideByZero
.
class Map
From Map
(Map) method Int
Defined as:
method Int(Map: --> Int)
Returns the number of pairs stored in the Map
(same as .elems
).
my = Map.new('a' => 2, 'b' => 17);say .Int; # OUTPUT: «2»
class IO::Path
From IO::Path
(IO::Path) method Int
Defined as:
method Int(IO::Path: --> Int)
Coerces .basename
to Int. Fails with X::Str::Numeric
if base name is not numerical.