In Hash§
See primary documentation in context for method of
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)»
In role QuantHash§
See primary documentation in context for 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.
In role Positional§
See primary documentation in context for method of
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)»
In Code§
See primary documentation in context for method of
method of(Code: --> Mu)
Returns the return type constraint of the Code
:
say -> () --> Int .of; # OUTPUT: «(Int)»
In Array§
See primary documentation in context for method of
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")»
In Scalar§
See primary documentation in context for method of
method of(Scalar: --> Mu)
Returns the type constraint of the container.
Example:
my Cool = 42;say .VAR.of; # OUTPUT: «(Cool)»
In role Associative§
See primary documentation in context for method of
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)»
In Variable§
See primary documentation in context for trait of
multi 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.