Last active
March 15, 2021 00:13
-
-
Save jasdev/2ad9c9d27929fd842fcfa01bcd1f079f to your computer and use it in GitHub Desktop.
`RangeReplaceableCollection.rotated(by:)` attempt w/ modulus issue.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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