Documentation for routine of

Documentation for routine of, assembled from the following types:

role Positional

From Positional

(Positional) method of

method of()

Returns the type constraint for elements of the positional container. Defaults to Mu.

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 @a1 = 1'two'3.14159;              # (no type constraint specified) 
say @a1.of;                              # OUTPUT: «(Mu)␤» 
 
my Int @a2 = 123;                    # (values must be of type Int) 
say @a2.of;                              # OUTPUT: «(Int)␤» 
@a2.push: 'd';
CATCH { default { put .^name''.Str } };
# OUTPUT: «X::TypeCheck::Assignment: Type check failed in assignment to @a2; expected Int but got Str ("d")␤» 

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 %h1 = 'apples' => 3'oranges' => 7;  # (no type constraint specified) 
say %h1.of;                              # OUTPUT: «(Mu)␤» 
 
my Int %h2 = 'oranges' => 7;             # (values must be of type Int) 
say %h2.of;                              # OUTPUT: «(Int)␤» 

class Scalar

From Scalar

(Scalar) method of

method of(Scalar:D: --> Mu)

Returns the type constraint of the container.

Example:

my Cool $x = 42;
say $x.VAR.of.^name;            # OUTPUT: «Cool» 

class Variable

From Variable

(Variable) trait of

multi sub trait_mod:<of>(Mu:U $targetMu:U $type)

Sets the type constraint of a container bound to a variable.

my $i of Int = 42;
$i = "forty plus two";
CATCH { default { say .^name' '.Str } }
# OUTPUT: «X::TypeCheck::Assignment Type check failed in assignment to $i; expected Int but got Str ("forty plus two")␤»