-
-
Save JJC1138/501ef8186cab49a8f780c2345cff94e7 to your computer and use it in GitHub Desktop.
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 Collection { | |
subscript(safe index: Index) -> Iterator.Element? { | |
var testIndex = startIndex | |
while testIndex != endIndex { | |
if testIndex == index { | |
return self[index] | |
} | |
testIndex = self.index(after: testIndex) | |
} | |
return nil | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment