<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">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?<div class=""><br class=""></div><div class="">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?'</div><div class=""><br class=""></div><div class="">let x = value if? condition</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">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:</div><div class=""><br class=""></div><div class="">let x = valueA if? conditionA ?? valueB if? conditionB ?? valueC</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Thanks,</div><div class="">Jon</div><div class=""><br class=""></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 5, 2015, at 9:09 AM, Chris Lattner <<a href="mailto:clattner@apple.com" class="">clattner@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Dec 4, 2015, at 11:43 AM, J. Cheyo Jimenez <<a href="mailto:cheyo@masters3d.com" class="">cheyo@masters3d.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class="">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. </div><div class=""><br class=""></div><div class="">Some interesting code in the standard library that uses the ternary operator quite a bit. </div><div class=""><br class=""></div><a href="https://gist.github.com/masters3d/7b0c6f3653368afe4357" class="">https://gist.github.com/masters3d/7b0c6f3653368afe4357</a><br class=""></div></div></blockquote><br class=""></div><div class="">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.</div><div class=""><br class=""></div><div class="">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.</div><div class=""><br class=""></div><div class="">-Chris</div><br class="">
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=vmG20pDvfvCvG17-2BDXZuJHKPrqKGMVaALNTeZHPMRaQp3j1P6QuloUW5-2Fz7ZaYWw44IJJ86yoXJwugVsQlV6kGzDh0i3zVP8NE-2B2bmdFzkGrSXChbkT-2FdBf-2B6BPYUrLT9t02kGtjBNpUoZC5-2FuJS5H3DdHX5-2FjKdgT6H4oo387YpR-2FoAjGxLfay-2BoDLg9SWrAKlOoD6tnET6bI7TVMF5lw-3D-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;" class="">
</div>
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></div></body></html>