rotate()
Consume the entire stream and emit its elements rotated either left or right
distance
number of spacesImplementation Notes
This implementation reads the entire stream before emitting any results making it inappropriate for infinite streams.
Signature
rotate(Rotate direction, long distance)
direction
- EitherLeft
orRight
distance
- Distance to rotate elements, may be positive or negative, may exceed input stream size
Examples
Rotate left positive distance
Stream
.of("A", "B", "C", "D", "E")
.gather(Gatherers4j.rotate(Rotate.Left, 2))
.toList();
// ["C", "D", "E", "A", "B"]
Rotate left negative distance
Stream
.of("A", "B", "C", "D", "E")
.gather(Gatherers4j.rotate(Rotate.Left, -2))
.toList();
// ["D", "E", "A", "B", "C"]
Rotate right positive distance
Stream
.of("A", "B", "C", "D", "E")
.gather(Gatherers4j.rotate(Rotate.Right, 2))
.toList();
// ["D", "E", "A", "B", "C"]
Rotate right negative distance
Stream
.of("A", "B", "C", "D", "E")
.gather(Gatherers4j.rotate(Rotate.Right, -2))
.toList();
// ["C", "D", "E", "A", "B"]