See Original text in context
method of(Code: --> Mu)
Returns the return type constraint of the Code
:
say -> () --> Int .of; # OUTPUT: «(Int)»
See Original text in context
method of()
Returns the type constraint for elements of the positional container, that is, the T
in the definition above, which, as it can be seen, defaults to Mu. It is returned as a type object.
my ;say .of.^name; # OUTPUT: «Mumy Str ;say .of.raku; # OUTPUT: «Str»say (my int @).of; # OUTPUT: «(int)»
See Original text in context
method of()
Associative
, as the definition above shows, 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 the key to Str
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)»
See Original text in context
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")»
See Original text in context
method of(Scalar: --> Mu)
Returns the type constraint of the container.
Example:
my Cool = 42;say .VAR.of; # OUTPUT: «(Cool)»
See Original text in context
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.
See Original text in context
method of(Hash:)
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)»
See Original text in context
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.