routine of
1 | class Code |
1.1 | (Code) method of |
2 | class Hash |
2.1 | (Hash) method of |
3 | class Scalar |
3.1 | (Scalar) method of |
4 | class Variable |
4.1 | (Variable) trait of |
5 | role Associative |
5.1 | (Associative) method of |
6 | class Array |
6.1 | (Array) method of |
7 | role QuantHash |
7.1 | (QuantHash) method of |
8 | role Positional |
8.1 | (Positional) method of |
Documentation for routine of
assembled from the following types:
class Code
From Code
(Code) method of
Defined as:
method of(Code: --> Mu)
Returns the return type constraint of the Code
:
say -> () --> Int .of; # OUTPUT: «(Int)»
class Hash
From Hash
(Hash) method of
Defined as:
method of()
Returns the type constraint for the values of the invocant. By default, i.e., if no type constraint is given during declaration, the method returns (Mu)
.
my = 'apples' => 3, 'oranges' => 7; # (no type constraint specified)say .of; # OUTPUT: «(Mu)»my Int = 'oranges' => 7; # (values must be of type Int)say .of; # OUTPUT: «(Int)»
class Scalar
From Scalar
(Scalar) method of
method of(Scalar: --> Mu)
Returns the type constraint of the container.
Example:
my Cool = 42;say .VAR.of; # OUTPUT: «(Cool)»
class Variable
From Variable
(Variable) trait of
multi sub trait_mod:<of>(Mu , Mu )
Sets the type constraint of a container bound to a variable.
my of Int = 42;= "forty plus two";CATCH# OUTPUT: «X::TypeCheck::Assignment Type check failed in assignment to $i; expected Int but got Str ("forty plus two")»
You can use any value defined in compile time as a type constraint, including constants:
constant \T = Int;my of T = 42;
which would be equivalent to the previous definition.
role Associative
From Associative
(Associative) method of
Defined as:
method of()
Associative
is actually a parameterized role which can use different classes for keys and values. As seen at the top of the document, by default it coerces to Str
for the key and uses a very generic Mu
for value.
my ;say .of;# OUTPUT: «(Mu)»
The value is the first parameter you use when instantiating Associative
with particular classes:
is Hash does Associative[Cool,DateTime] ;my := DateHash.new;say .of; # OUTPUT: «(Cool)»
class Array
From Array
(Array) method of
Defined as:
method of
Returns the type constraint for the values of the invocant. By default, i.e. if no type constraint is given during declaration, the method returns (Mu)
.
my = 1, 'two', 3.14159; # (no type constraint specified)say .of; # OUTPUT: «(Mu)»my Int = 1, 2, 3; # (values must be of type Int)say .of; # OUTPUT: «(Int)».push: 'd';CATCH ;# OUTPUT: «X::TypeCheck::Assignment: Type check failed in assignment to @a2; expected Int but got Str ("d")»
role QuantHash
From QuantHash
(QuantHash) method of
method of()
Returns the type of value a value of this QuantHash
may have. This is typically Bool for Setty, UInt for Baggy or Real for Mixy roles.
role Positional
From Positional
(Positional) method of
method of()
Returns the type constraint for elements of the positional container. Defaults to Mu.