Skip to content

Commit 69c11e2

Browse files
authored
Feat/implement safe collection (#2)
* [Add] allow collection subscript nil
1 parent b944f45 commit 69c11e2

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Sources/LodyExtensions/Foundation/Collection/Collection+Ex.swift

+4
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,8 @@ public extension Collection where Element: Hashable {
1111
let unique = Set(self)
1212
return Array(unique)
1313
}
14+
15+
subscript (safe index: Index) -> Element? {
16+
return indices.contains(index) ? self[index] : nil
17+
}
1418
}

0 commit comments

Comments
 (0)