How do you rotate (circular shift) of a Scala collection
I can do this quite easily, and cleanly, using a for loop. For instance, if I wanted to traverse a Seq from every element back to itself I would do the following: val seq = Seq(1,2,3,4,5) for (i <- seq.indices) { for (j <- seq.indices) { print(seq(i + j % seq.length)) } } But as I'm looking to fold over the collection, I'm wondering if there is a more idiomatic approach. A recursive approach would allow me to avoid any var s. But basically, I'm wondering if something like the following is possible: seq.rotatedView(i) Which would create a rotated view, like rotating bits (or circular shift).