Skip to content

Instantly share code, notes, and snippets.

@Marcocanc
Created April 17, 2017 09:04
Show Gist options
  • Save Marcocanc/b86290615507c66be8c8e916a65444e3 to your computer and use it in GitHub Desktop.
Save Marcocanc/b86290615507c66be8c8e916a65444e3 to your computer and use it in GitHub Desktop.
extension Collection {
public subscript(safe index: Index) -> Optional<Iterator.Element> {
guard self.startIndex..<self.endIndex ~= index else { return nil }
return self[index]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment