Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Adds rotor refs #1731
  • Loading branch information
JJ committed Feb 19, 2019
1 parent 7f98d42 commit e642731
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions doc/Type/Any.pod6
Expand Up @@ -1261,6 +1261,37 @@ Coerces the invocant to a C<list> by applying
its L«C<.list>|/routine/list» method and uses
L«C<List.batch>|/type/List#method_batch» on it.
=head2 method rotor
Defined as:
multi method rotor(Any:D: Int:D $batch, :$partial)
multi method rotor(Any:D: *@cycle, :$partial)
Groups the elements of the object in lists of C<$batch> elements.
say (3..9).rotor(3); # OUTPUT: «((3 4 5) (6 7 8))␤»
With the C<:partial> named argument, it will also include lists that do not get
to be the C<$batch> size:
say (3..10).rotor(3, :partial); # OUTPUT: «((3 4 5) (6 7 8) (9 10))␤»
C<.rotor> can be called with an array of integers and pairs, which will be
applied in turn. While integers will establish the batch size, as above,
C<Pair>s will use the key as batch size and the value as number of elements to
skip if it's positive, or overlap if it's negative.
say (3..11).rotor(3, 2 => 1, 3 => -2, :partial);
# OUTPUT: «((3 4 5) (6 7) (9 10 11) (10 11))␤»
In this case, the first batch (ruled by an integer) has 3 elements; the second
one has 2 elements (key of the pair), but skips one (the number 8); the third
one has size 2 (because partials are allowed), and an overlap of 2 also.
Please see also L<C<list.rotor>|/type/List#method_rotor> for examples applied to
lists.
=end pod

# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6

0 comments on commit e642731

Please sign in to comment.