[swift-evolution] ternary operator ?: suggestion
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
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution