Skip to content

Commit a1f0ae3

Browse files
committed
Be more specific about Any.Hash|hash
- make clear that .hash returns *something* Associative - point to .Hash / .Map if you want mutable / immutable - fix obviously wrong example
1 parent 8fe5c51 commit a1f0ae3

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

doc/Type/Any.pod6

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,7 @@ Defined as:
363363
proto method Hash(|) is nodal
364364
multi method Hash( --> Hash:D)
365365
366-
367-
Coerce the invocant to L<Hash> by invoking the method C<hash> on it.
366+
Coerce the invocant to L<Hash>.
368367
369368
=head2 method hash
370369
@@ -374,15 +373,23 @@ Defined as:
374373
multi method hash(Any:U: --> Hash:D)
375374
multi method hash(Any:D: --> Hash:D)
376375
377-
Creates a new L<Hash|/type/Hash>, empty in the case the invocant is
378-
undefined, or coerces the invocant to an C<Hash> in the case it is
379-
defined.
376+
Coerces a type object to an empty L<Hash>.
377+
378+
More generally, coerces a defined invocant to something that supports the
379+
L<Associative> role. This may be a mutable L<Hash>, but may also be
380+
an immutable L<Map> or anything else that supports the L<Associative>
381+
role. Use the C<.Hash> method if you really want to have a mutable L<Hash>,
382+
or the C<.Map> coercer if you're happy enough with an immutable L<Map>.
383+
Use the C<.hash> coercer if you really don't care and want the cheapest
384+
way to get an object that does the L<Associative> role.
380385
381386
=begin code
382387
my $d; # $d is Any
383388
say $d.hash; # OUTPUT: {}
384-
$d.append: 'a', 'b';
385-
say $d.hash; # OUTPUT: {a => b}
389+
390+
my %m is Map = a => 42, b => 666;
391+
say %m.hash; # Map.new((a => 42, b => 666))
392+
say %m.Hash; # {a => 42, b => 666}
386393
=end code
387394
388395
=head2 method Slip

0 commit comments

Comments
 (0)