[swift-evolution] ternary operator ?: suggestion

Alex Lew alexl.mail+swift at gmail.com
Sun Dec 6 16:14:54 CST 2015


👍

On Sun, Dec 6, 2015 at 5:12 PM, thorsten at portableinnovations.de <
thorsten at portableinnovations.de> wrote:

> Absolutely. Just the same rule: parts that were statements must be
> expressions. The else clause becomes mandatory.
>
> -Thorsten
>
> Am 06.12.2015 um 22:52 schrieb Alex Lew <alexl.mail+swift at gmail.com>:
>
> 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/3fb93a4b/attachment.html>


More information about the swift-evolution mailing list