Skip to content

Instantly share code, notes, and snippets.

@lacyrhoades
Last active October 5, 2017 16:46
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 lacyrhoades/fa2f4e5ef31f6ed29c69cd4eda98b477 to your computer and use it in GitHub Desktop.
Save lacyrhoades/fa2f4e5ef31f6ed29c69cd4eda98b477 to your computer and use it in GitHub Desktop.
Circular iterator in Swift
extension IndexingIterator {
mutating func next(wrapping: Bool) -> IndexingIterator.Element? {
if let result = self.next() {
return result
} else {
self = self.makeIterator()
return self.next()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment