Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added docs for List.Capture. gfldex++, perlpilot++, ab6tract++
  • Loading branch information
Jan-Olof Hendig committed Jul 19, 2016
1 parent bb57c6d commit 59cb8ea
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions doc/Type/List.pod6
Expand Up @@ -500,6 +500,41 @@ Usage:
Returns the number of elements in the list (same as C<.elems>).
=head2 method Capture
Defined as:
method Capture() returns Capture:D
Usage:
LIST.Capture
Returns a L<Capture|/type/Capture> where each L<Pair|/type/Pair>, if any, in
the C<List> has been converted to a named argument. All other elements in the
C<List> are converted to positional arguments in the order they are found,
i.e. the first non pair item in the list becomes the first positional argument,
which gets index C<0>, the second non pair item becomes the second positional
argument, getting index C<1> etc.
my $list = (7, 5, a => 2, b => 17);
my $capture = $list.Capture;
say $capture.keys; # (0 1 a b)
my-sub(|$capture); # 7, 5, 2, 17
sub my-sub($first, $second, :$a, :$b) {
say "$first, $second, $a, $b"
}
A more advanced example demonstrating the returned C<Capture> being matched
against a L<Signature|type/Signature>.
my $list = (7, 5, a => 2, b => 17);
say so $list.Capture ~~ :($ where * == 7,$,:$a,:$b); # True
$list = (8, 5, a => 2, b => 17);
say so $list.Capture ~~ :($ where * == 7,$,:$a,:$b); # False
=head2 routine pick
Defined as:
Expand Down

0 comments on commit 59cb8ea

Please sign in to comment.