CollectionExtension.swift (345B)
1 // 2 // CollectionExtension.swift 3 // damus 4 // 5 // Created by Daniel D’Aquino on 2023-11-25. 6 // 7 8 import Foundation 9 10 extension Collection { 11 /// Returns the element at the specified index if it is within bounds, otherwise nil. 12 subscript (safe index: Index) -> Element? { 13 return indices.contains(index) ? self[index] : nil 14 } 15 }