Correct, it is not ternary, just a slip of my mind :)
I have a great amount of understanding for that, I find `nil coalescing 
operator` name simply impossible to remember :)



I didn’t know this workaround worked. Cool! Can somebody from the core team 
tell us if it not supporting throw directly is a bug or an intended feature?
Just to elaborate a little after I thought about it for a minute: intended 
feature. The core reason is that `throw` is a statement (the same way as `if` 
or `guard` are), and in Swift statements are not expressions. `try`, on the 
other hand, is an expression.

So you cannot simply `throw` the same way you cannot write:

let elem : AnyObject = “42"
let int = elem as? Int ?? if true { return 42 }
but you can write:

let elem : AnyObject = “42”

let int = elem as? Int ?? { if true { return 42 } }()

There has been already a few discussions whether statements should be 
expressions in swift or not on the list, which I’ve been only partially 
following, so I’m not sure if there’re any plans for changing the current 
statement/expression tradeoff is Swift :)

Cheers!

Krzysztof

_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to