Documentation for method rotor

Documentation for method rotor, assembled from the following types:

class List

From List

(List) method rotor

Defined as:

method rotor(*@cycleBool() :$partial --> Seq:D)

Returns a sequence of lists, where each sublist is made up of elements of the invocant.

In the simplest case, @cycle contains just one integer, in which case the invocant list is split into sublists with as many elements as the integer specifies. If :$partial is True, the final chunk is included even if it doesn't satisfy the length requirement:

say ('a'..'h').rotor(3).join('|');              # OUTPUT: «a b c|d e f␤» 
say ('a'..'h').rotor(3:partial).join('|');    # OUTPUT: «a b c|d e f|g h␤» 

If the element of @cycle is a Pair instead, the key of the pair specifies the length of the return sublist, and the value the gap between sublists; negative gaps produce overlap:

say ('a'..'h').rotor(2 => 1).join('|');         # OUTPUT: «a b|d e|g h␤» 
say ('a'..'h').rotor(3 => -1).join('|');        # OUTPUT: «a b c|c d e|e f g␤» 

If @cycle contains more than element, rotor cycles through it to find the number of elements for each sublist:

say ('a'..'h').rotor(23).join('|');           # OUTPUT: «a b|c d e|f g␤» 
say ('a'..'h').rotor(1 => 13).join('|');      # OUTPUT: «a|c d e|f␤» 

Combining multiple cycles and :partial also works:

say ('a'..'h').rotor(1 => 13 => -1:partial).join('|');
# OUTPUT: «a|c d e|e|g h␤» 

See this blog post for more elaboration on rotor.

class Supply

From Supply

(Supply) method rotor

method rotor(Supply:D: @cycle --> Supply:D)

Creates a "rotoring" supply with the same semantics as List.rotor.