This branches off “Blasts from the past: algorithms.” Hopefully we’ll have a rotate(toStartAt:)
, and maybe a rotate(toEndAfter:)
. Those use an endpoint to base the rotation amount, instead of an number. Maybe we should have an count-based rotate too.
-
rotate(towardsStart count: IndexDistance)
- Acts like
rotate(towardsEnd: -count)
whencount < 0
. - No-op if
self.count <= 1
. - Does
rotate(toStartAt: index(startIndex, offset: count % self.count))
.
- Acts like
-
rotate(towardsEnd count: IndexDistance)
- Acts like
rotate(towardsStart: -count)
whencount < 0
. - No-op if
self.count <= 1
. - Does
rotate(toEndAfter: index(endIndex, offset: -((count + 1) % self.count)))
.
- Acts like
The methods besides rotate(toStartAt:)
could be hard-coded extension methods. I don’t know if the remaining one should be hard-coded, or a potential override point.