[swift-evolution] ternary operator ?: suggestion

Angelo Villegas gelo.web at gmail.com
Tue Dec 22 09:25:41 CST 2015


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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151222/4ae34083/attachment.html>


More information about the swift-evolution mailing list