Without trying to upset this apple cart. Let's simply review the code sample you provided:
for i in maybeHugeRange?.reversed() ?? [] { // doom occurs here
print(i) // your app will jetsam without ever reaching here
break
}
...and consider an alternative method like Rust's unwrap_or
. I'll use the simple code sample I provide earlier:
extension Optional {
func ifSome(orElse: Wrapped) -> Wrapped {
switch self {
case .some(let wrapped): return wrapped
case .none: return orElse
}
}
}
Trying to do this kind of this isn't possible re "Left side of nil coalescing operator '??' has non-optional type '[Int]', so the right side is never used"
for i in maybeHugeRange.ifSome(orElse: 0..<0).reversed() ?? [] {
print(i) // your app will jetsam without ever reaching here
break
}
So maybe I'm missing the obvious here... how exactly does the method end up with the same issue.