Skip to content

Commit

Permalink
Document roundrobin
Browse files Browse the repository at this point in the history
... wantonly stealing from the specs
  • Loading branch information
Paul Cochrane committed Mar 21, 2015
1 parent 5f9e753 commit 46e6edf
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions lib/Type/List.pod
Expand Up @@ -516,14 +516,31 @@ by the signature:
say "Name: $name; Zip code: $zip";
}
By default the C<zip> function reads to the end of the shortest list,
but a short list may always be extended arbitrarily by putting C<*>
after the final value, which replicates the final value as many times
as necessary. If instead of supplying a default value for short lists,
you just wish to skip missing entries, use C<roundrobin> instead:
By default the C<zip> function reads to the end of the shortest list, but a
short list may always be extended arbitrarily by putting C<*> after the
final value, which replicates the final value as many times as necessary.
If instead of supplying a default value for short lists, you just wish to
skip missing entries, use L<roundrobin|/type/List#sub_roundrobin> instead:
for roundrobin(@queue1; @queue2; @queue3) -> $next {
...
}
=head2 sub roundrobin
multi roundrobin(List:D: --> Parcel)
C<roundrobin> is very similar to L<zip|/type/List#routine_zip>. The
difference is that C<roundrobin> will not stop on lists that run out of
elements but simply skip any undefined value:
my @a = 1;
my @b = 1..2;
my @c = 1..3;
for roundrobin(@a; @b; @c) -> $x { $x.say }
will display the following values: C<1, 1, 1, 2, 2, 3>
=end pod

# vim: expandtab shiftwidth=4 ft=perl6

0 comments on commit 46e6edf

Please sign in to comment.