Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jasdev
Created March 14, 2021 03:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasdev/7568288f7a7721bdadf95f022da44ece to your computer and use it in GitHub Desktop.
Save jasdev/7568288f7a7721bdadf95f022da44ece to your computer and use it in GitHub Desktop.
Collection.rotated(toStartAt:) approach.
extension Collection {
func rotated(toStartAt newStart: Index) -> AnyCollection<Element> {
self[newStart...] + self[..<newStart] // ❌ “Cannot convert return
// expression of type `SubSequence` to return type `AnyCollection<Element>`.”
//
// ❌ “Referencing operator function `+` on `RangeReplaceableCollection`
// requires that `SubSequence` conform to `RangeReplaceableCollection`.”
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment