@@ -1261,6 +1261,37 @@ Coerces the invocant to a C<list> by applying
1261
1261
its L « C < .list > |/routine/list» method and uses
1262
1262
L « C < List.batch > |/type/List#method_batch» on it.
1263
1263
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
+
1264
1295
= end pod
1265
1296
1266
1297
# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6
0 commit comments