Created
October 12, 2020 06:31
-
-
Save Kievkao/8a1ab5753af0e29d80ca1405f1996df9 to your computer and use it in GitHub Desktop.
Safe collections access
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) -> Element? { | |
return indices.contains(index) ? self[index] : nil | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment