Last active
February 29, 2020 10:20
-
-
Save jeffery812/e451e4bc73b1d768cbd3e5667258d76c to your computer and use it in GitHub Desktop.
Returns the element at the specified index if it is within bounds, otherwise nil.
This file contains hidden or 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
public extension Collection { | |
/// Returns the element at the specified index if it is within bounds, otherwise nil. | |
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