Skip to content

Commit e642731

Browse files
committed
Adds rotor refs #1731
1 parent 7f98d42 commit e642731

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

doc/Type/Any.pod6

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,6 +1261,37 @@ Coerces the invocant to a C<list> by applying
12611261
its L«C<.list>|/routine/list» method and uses
12621262
L«C<List.batch>|/type/List#method_batch» on it.
12631263
1264+
=head2 method rotor
1265+
1266+
Defined as:
1267+
1268+
multi method rotor(Any:D: Int:D $batch, :$partial)
1269+
multi method rotor(Any:D: *@cycle, :$partial)
1270+
1271+
Groups the elements of the object in lists of C<$batch> elements.
1272+
1273+
say (3..9).rotor(3); # OUTPUT: «((3 4 5) (6 7 8))␤»
1274+
1275+
With the C<:partial> named argument, it will also include lists that do not get
1276+
to be the C<$batch> size:
1277+
1278+
say (3..10).rotor(3, :partial); # OUTPUT: «((3 4 5) (6 7 8) (9 10))␤»
1279+
1280+
C<.rotor> can be called with an array of integers and pairs, which will be
1281+
applied in turn. While integers will establish the batch size, as above,
1282+
C<Pair>s will use the key as batch size and the value as number of elements to
1283+
skip if it's positive, or overlap if it's negative.
1284+
1285+
say (3..11).rotor(3, 2 => 1, 3 => -2, :partial);
1286+
# OUTPUT: «((3 4 5) (6 7) (9 10 11) (10 11))␤»
1287+
1288+
In this case, the first batch (ruled by an integer) has 3 elements; the second
1289+
one has 2 elements (key of the pair), but skips one (the number 8); the third
1290+
one has size 2 (because partials are allowed), and an overlap of 2 also.
1291+
1292+
Please see also L<C<list.rotor>|/type/List#method_rotor> for examples applied to
1293+
lists.
1294+
12641295
=end pod
12651296

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

0 commit comments

Comments
 (0)