mirror of
https://github.com/dscyrescotti/Memola.git
synced 2026-03-26 19:31:18 +01:00
22 lines
406 B
Swift
22 lines
406 B
Swift
//
|
|
// Collection++.swift
|
|
// Memola
|
|
//
|
|
// Created by Dscyre Scotti on 5/4/24.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
extension Collection {
|
|
subscript(safe index: Index) -> Element? {
|
|
return indices.contains(index) ? self[index] : nil
|
|
}
|
|
}
|
|
|
|
extension Collection where Index == Int {
|
|
subscript(fromEnd index: Index) -> Element? {
|
|
let i = count - (index + 1)
|
|
return self[safe: i]
|
|
}
|
|
}
|