Skip to content

Commit 3813c8e

Browse files
committed
show how to slip a complex Hash into named arguments
1 parent 65d800b commit 3813c8e

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

doc/Type/Signature.pod6

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,12 +453,21 @@ L<Pair|/type/Pair> with C<|> to turn it into a named argument.
453453
my $pair = :named(1);
454454
f |$pair; # «(:$named)␤»
455455
456-
The same can be used to convert a Hash into named arguments.
456+
The same can be used to convert a C<Hash> into named arguments.
457457
458458
my %pairs = also-named => 4;
459459
sub f(|c) {};
460460
f |%pairs; # «(:$also-named)␤»
461461
462+
A C<Hash> that contains a list may prove problematic when slipped into named
463+
arguments. To avoid the extra layer of containers coerce to L<Map|/type/Map>
464+
before slipping.
465+
466+
class C { has $.x; has $.y; has @.z };
467+
my %h = <x y z> Z=> (5, 20, [1,2]);
468+
say C.new(|%h.Map);
469+
# OUTPUT«C.new(x => 5, y => 20, z => [1, 2])␤»
470+
462471
X<|optional argument (Signature)>
463472
=head2 Optional and Mandatory Parameters
464473

0 commit comments

Comments
 (0)