Currently, the shortest syntax to throw an error on unsuccesful Optional unwrap is try someOptional ?? { throw SomeError() }()
.
While the closure wrapping isnt too bad, this feels like the perfect match for the use of @autoclosure. Nil-coalescing is already lazy, but making the rhs @autoclosure allows us to strip the ugly {...}()
syntax. Afterall, if we were to do this with a custom operator, like objc.io do here https://twitter.com/objcio/status/1100437285684822017?s=21 , we would likely make rhs @autoclosure as well.
What do you guys think? To me it feels like a natural use for Swift’s existing @autoclosure feature, and a purely additive change that doesnt really break any reasonable code. I havent researched the current implementation of ?? in detail, but will do if these forums think its something worth pursuing.