[swift-evolution] ternary operator ?: suggestion

Matthew Johnson matthew at anandabits.com
Tue Dec 22 09:36:58 CST 2015


This looks reasonable in declarations but how would it work in expressions?  Or are you suggesting that it is only usable for declarations?

Sent from my iPad

> On Dec 22, 2015, at 9:25 AM, Angelo Villegas via swift-evolution <swift-evolution at swift.org> wrote:
> 
> I for one feels like the ternary operator still has a future with Swift.
> 
> If the discussion with ternary will go on though, I would like to weigh in a suggestion:
> 
>     let a | x == y = a
>           | otherwise = b
> 
>     let b | colour.Red = 0xff0000
>           | colour.Green = 0x00ff00
>           | colour.Blue = 0x0000ff
>           | otherwise = 0x000000
> 
> My rule of thumb for a style like this is that if you can read it as if it was English (read | (bar) as "when", | otherwise (bar otherwise) as "otherwise" and = as "is" or "be"), you're probably doing something right.
> 
> _______________________________________________
> 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/20151222/80752adf/attachment.html>


More information about the swift-evolution mailing list