method keyof
1 | class Hash |
1.1 | (Hash) method keyof |
2 | role Associative |
2.1 | (Associative) method keyof |
3 | role QuantHash |
3.1 | (QuantHash) method keyof |
Documentation for method keyof
assembled from the following types:
class Hash
From Hash
(Hash) method keyof
Defined as:
method keyof()
Returns the type constraint for the keys of the invocant. For normal hashes the method returns the coercion type (Str(Any))
while for non-string keys hashes the type used in the declaration of the Hash
is returned.
my = 'apples' => 3, 'oranges' => 7; # (no key type specified)say .keyof; # OUTPUT: «(Str(Any))»my = 'oranges' => 7; # (keys must be of type Str)say .keyof; # (Str)= 'apples'; # throws exceptionCATCH ;# OUTPUT: «X::TypeCheck::Binding: Type check failed in binding to key; expected Str but got Int (3)»my ; # (this time, keys must be of type Int)= 4096;say .keyof; # (Int)
role Associative
From Associative
(Associative) method keyof
Defined as:
method keyof()
Returns the parameterized key used for the Associative role, which is Any
coerced to Str
by default. This is the class used as second parameter when you use the parameterized version of Associative.
my ;.keyof; #OUTPUT: «(Str(Any))»
role QuantHash
From QuantHash
(QuantHash) method keyof
method keyof()
Returns the type of value a key of this QuantHash
may have. This is typically Mu.