Skip to content

Commit 09f25db

Browse files
authored
Add example in method keysof
1 parent b9531b2 commit 09f25db

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

doc/Type/Hash.pod6

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,8 +582,8 @@ Defined as:
582582
583583
Returns the type constraint for the keys of the invocant. For
584584
normal hashes the method returns the coercion type C<(Str(Any))>
585-
while for L<object hashes|/type/Hash#Object_hashes_and_type_constraints>
586-
the type used in the declaration of the C<Hash> is returned.
585+
while for L<non-string keys|/type/Hash#Non-string_keys>
586+
hashes the type used in the declaration of the C<Hash> is returned.
587587
588588
my %h1 = 'apples' => 3, 'oranges' => 7; # (no key type specified)
589589
say %h1.keyof; # OUTPUT: «(Str(Any))␤»
@@ -594,6 +594,10 @@ the type used in the declaration of the C<Hash> is returned.
594594
CATCH { default { put .^name, ': ', .Str } };
595595
# OUTPUT: «X::TypeCheck::Binding: Type check failed in binding to key; expected Str but got Int (3)␤»
596596
597+
my %h3{Int}; # (this time, keys must be of type Int)
598+
%h3{42} = 4096;
599+
say %h3.keyof; # (Int)
600+
597601
=head2 method of
598602
599603
Defined as:

0 commit comments

Comments
 (0)