[swift-evolution] ternary operator ?: suggestion
Alex Lew
alexl.mail+swift at gmail.com
Sun Dec 6 15:52:01 CST 2015
I agree that it's simplest to just reuse switch keyword, and keep braces.
+1.
Would you allow the same thing with if?
let thisColor = if condition { .Red } else { .Blue }
On Sun, Dec 6, 2015 at 4:44 PM, Rudolf Adamkovic <salutis at me.com> wrote:
> > On 06 Dec 2015, at 22:35, thorsten--- via swift-evolution <
> swift-evolution at swift.org> wrote:
>
> >
> > I would prefer the expression to match the statement. The only
> difference would be that all parts that were statements now have to be
> expressions.
>
> +1
>
> >
> > Therefore the switch-expression should simply look like follows:
> >
> > let thisColor = switch thatColor {
> > case .Red: .Green // must be an expression
> > default: .Yellow // must be an expression
> > }
> >
> > No returns needed in the case clauses.
>
> This actually looks great. One simple rule and zero new keywords.
>
> Readable and simple to learn.
>
> Fantastic!
>
> > Formatting this as a one-liner would just require adding semicolons
> (though I wouldn't recommend this).
> >
> > -Thorsten
> > _______________________________________________
> > swift-evolution mailing list
> > swift-evolution at swift.org
> > https://lists.swift.org/mailman/listinfo/swift-evolution
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151206/9423de10/attachment.html>
More information about the swift-evolution
mailing list