[swift-evolution] ternary operator ?: suggestion
jhull at gbis.com
Sat Dec 5 17:28:21 CST 2015
I think I have a solution for the ternary part, but I am not sure I fully understand what is being asked for in the case of switch. Could someone clarify?
There is another thread which goes into the idea a little more, but the basic idea is that we replace the ternary operator with ‘if?'
let x = value if? condition
If condition is true, then x is value… otherwise it is nil. You can combine with the nil-coalescing operator to get else and else if style behavior:
let x = valueA if? conditionA ?? valueB if? conditionB ?? valueC
> On Dec 5, 2015, at 9:09 AM, Chris Lattner <clattner at apple.com> wrote:
>> On Dec 4, 2015, at 11:43 AM, J. Cheyo Jimenez <cheyo at masters3d.com <mailto:cheyo at masters3d.com>> wrote:
>> I'd like some feedback from the core team to see if eliminating the ternary operator and replacing it with if-else is even proposal worthy.
>> Some interesting code in the standard library that uses the ternary operator quite a bit.
>> https://gist.github.com/masters3d/7b0c6f3653368afe4357 <https://gist.github.com/masters3d/7b0c6f3653368afe4357>
> FWIW, I have no love for the ternary operator (it is totally "bizarre C magic”), but it does solve a problem that Swift currently otherwise has no solution for.
> If you’re interested in pursuing this, then the right path forward is to build a holistic proposal to turn statements (like if and switch) into expressions. This is subtle and requires thought, but is widely desired and if someone were interested in driving the design and implementation, then I’d be interested to see it happen.
> swift-evolution mailing list
> swift-evolution at swift.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution