Skip to content

Commit 8e29886

Browse files
committed
Merge pull request #315 from gfldex/master
doc casting a Hash or Pair into named arguments (sammers++)
2 parents c8961ab + 3d81284 commit 8e29886

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

doc/Type/Signature.pod

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,24 @@ variable name:
276276
Aliases are also possible that way:
277277
278278
sub paint( :color(:colour($c)) ) { } # 'color' and 'colour' are both OK
279-
sub paint( :color(:$colour) ) { } # same API for the caller
279+
sub paint( :color(:$colour) ) { } # same API for the caller
280+
281+
A function with named arguments can be called dynamically, dereferencing a
282+
Pair with C<|> to turn it into a named argument.
283+
284+
multi f(:$named){ note &?ROUTINE.signature };
285+
multi f(:$also-named){ note &?ROUTINE.signature };
286+
for 'named', 'also-named' -> $n {
287+
f(|($n => rand)) # «(:$named)␤(:$also-named)␤»
288+
}
289+
290+
my $pair = :named(1);
291+
f |$pair; # «(:$named)␤»
292+
293+
The same can be used to convert a Hash into named arguments.
294+
295+
my %pairs = also-named => 4;
296+
f |%pairs; # «(:$also-named)␤»
280297
281298
=head2 Optional and Mandatory Parameters
282299

0 commit comments

Comments
 (0)