[swift-evolution] ternary operator ?: suggestion

Thorsten Seitz thorsten.seitz at web.de
Sun Dec 6 10:25:07 CST 2015


> Am 06.12.2015 um 01:28 schrieb Alex Lew via swift-evolution <swift-evolution at swift.org>:
> 
> I don't think you can just get rid of the if statement in favor of an expression. You still want to be able to do this:
> 
> if (condition) {
>     funcWithSideEffectsThatReturnsInt()
> } else {
>     funcWithSideEffectsThatReturnsString()
> }
> 
> but that's not a valid expression (what is its type?).

That would actually be no problem if Swift’s type system would have union types (Ceylon has union and intersection types which are quite awesome and enable lots of nice things quite naturally, see http://ceylon-lang.org/documentation/1.2/tour/types/).

In that case the type of such an expression would just be the union of both types, which is written Int | String in Ceylon.

-Thorsten

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151206/6a725920/attachment.html>


More information about the swift-evolution mailing list