Last active
October 5, 2017 16:46
-
-
Save lacyrhoades/fa2f4e5ef31f6ed29c69cd4eda98b477 to your computer and use it in GitHub Desktop.
Circular iterator in Swift
This file contains 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 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