nicpro85
(Nicolas Manzini)
1
What do you think about this:
let firstElement = list.first() !? return
let firstElement = list.first() !? break
let firstElement = list.first() !? continue
I know this is a common topic. It's just one more attempt at finding a shorthand for the famous guard let else empty return statement.
1 Like
nicpro85
(Nicolas Manzini)
3
let firstElement = list.first() ?? "defaultValue"
let firstElement = list.first() !? return
the second would be the same as
guard let firstElement = list.first() else {
return
}
xwu
(Xiaodi Wu)
4
Abbreviating guard...else with new syntax is a commonly rejected change. This particular suggestion hasn’t been listed in the document on such changes, but it would fall under the same umbrella as the others, I would think.
mattpolzin
(Mathew Polzin)
5
On the other hand, see future directions at the end of the original post of this thread: Uninhabited Type (Never) Conversions
[EDIT] Note that the above linked thread is not an accepted direction for the language, it’s just a discussion.
Not sure I would want to be able to avoid guard statements where I’d otherwise be returning or continuing but the idea of throwing if nil coalescing fails is appealing to me.