[swift-evolution] ternary operator ?: suggestion

Matthew Johnson matthew at anandabits.com
Tue Jan 5 12:41:23 CST 2016


> On Jan 5, 2016, at 12:37 PM, Marcelo Alves via swift-evolution <swift-evolution at swift.org> wrote:
> 
> 
>> On Jan 5, 2016, at 16:06, Thorsten Seitz via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> 
>> 
>>> Am 05.01.2016 um 18:12 schrieb Matthew Johnson <matthew at anandabits.com <mailto:matthew at anandabits.com>>:
>>> 
>>>>>>> On Jan 5, 2016, at 12:29 AM, Thorsten Seitz via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>>>>>> 
>>>>>>> I once suggested the following ternary like switch:
>>>>>>> 
>>>>>>> let x = color ?
>>>>>>>      case .Red: 0xFF0000
>>>>>>>      case .Green: 0x00FF00
>>>>>>>      case .Blue: 0x0000FF 
>>>>>>>      default: 0xFFFFFF
>>>>>> 
>>>>>> 
>>> 
>>> Is anybody going to write up a proposal for the ternary-like switch expression?
>>> 
>> 
>> I’ll give it a try.
> 
> Any reason to not use switch let x = color … ? We already have if let, guard let, so I think switch let is pretty “swift-ly”.

Because this would only work when binding a name and not anywhere else.  If that restriction is desired this might not be a bad idea.  But if we want an expression that can be used anywhere it will not suffice.

> 
> :: marcelo.alves
> 
> _______________________________________________
> 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/20160105/620e5836/attachment.html>


More information about the swift-evolution mailing list