1
1
mirror of https://github.com/github/semantic.git synced 2024-12-24 23:42:31 +03:00

Array Prism subscripting is safe.

This commit is contained in:
Rob Rix 2015-09-21 15:42:07 -04:00
parent 0eca419468
commit fda61501e1

View File

@ -92,7 +92,12 @@ extension Array : ArrayType {
extension Prism where To : ArrayType {
subscript (index: Int) -> Prism<From, To.Element> {
return self >>> Prism<To, To.Element>(forward: { $0.array[index] }, backward: { To(array: [ $0 ]) })
return self >>> Prism<To, To.Element>(
forward: {
let array = $0.array
return array.count > index ? array[index] : nil
},
backward: { To(array: [ $0 ]) })
}
}