Skip to content

Commit

Permalink
Merge pull request #2 from stonko1994/feature/add-array-safe
Browse files Browse the repository at this point in the history
Add `Array+Safe`
  • Loading branch information
stonko1994 authored Jun 23, 2023
2 parents e18b89e + 3876c79 commit 5e420b4
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Sources/PowerPack/Array+Safe/Array+Safe.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Foundation

extension Array {
subscript(safe index: Int) -> Element? {
guard index >= startIndex, index < endIndex else {
return nil
}

return self[index]
}
}

0 comments on commit 5e420b4

Please sign in to comment.