Skip to content

Instantly share code, notes, and snippets.

@ebubekirsezer
Created October 20, 2022 22:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ebubekirsezer/e9f4c82e711fe39dcedd8bfa809948b4 to your computer and use it in GitHub Desktop.
Save ebubekirsezer/e9f4c82e711fe39dcedd8bfa809948b4 to your computer and use it in GitHub Desktop.
import Foundation
extension Collection {
func arrayValue<T>() -> [T] where Self.Element == T {
guard self.count > 0 else { return [] }
var list: [T] = []
list.append(contentsOf: self)
return list
}
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