ctietze, 1 year ago @nicklockwood indices.contains is interesting. It makes absolute sense. This could be O(n) instead of O(1), compared to @ericasadun's old extension0 I kept around since 2015: extension Array { subscript (safe index: UInt) -> Element? { return Int(index) < count ? self[Int(index)] : nil } } -- but that's surely irrelevant. If that kind of performance matters, one wouldn't use this subscript anyway.
@nicklockwood indices.contains is interesting. It makes absolute sense.
indices.contains
This could be O(n) instead of O(1), compared to @ericasadun's old extension0 I kept around since 2015:
extension Array { subscript (safe index: UInt) -> Element? { return Int(index) < count ? self[Int(index)] : nil } }
-- but that's surely irrelevant. If that kind of performance matters, one wouldn't use this subscript anyway.