Skip to content

Instantly share code, notes, and snippets.

@jasdev
Last active March 15, 2021 00:13
Show Gist options
  • Save jasdev/2ad9c9d27929fd842fcfa01bcd1f079f to your computer and use it in GitHub Desktop.
Save jasdev/2ad9c9d27929fd842fcfa01bcd1f079f to your computer and use it in GitHub Desktop.
`RangeReplaceableCollection.rotated(by:)` attempt w/ modulus issue.
extension RangeReplaceableCollection where Index: BinaryInteger {
func rotated(by offset: Index) -> SubSequence {
guard !isEmpty else { return .init() }
let shiftPoint = offset % endIndex
return self[shiftPoint...] + self[..<shiftPoint]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment