A non in-place version of rotate?

The lazy version is composable by chaining two slices together:

let c = [10, 20, 30, 40, 50]
let p = 2
let rotated = c[p...].chained(with: c[..<p])

However, a custom Rotated wrapper type can support (1) providing the starting index of the original collection and (2) handling re-rotation without slicing / chaining again.

2 Likes