<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 29, 2015, at 8:54 AM, Charles Constant &lt;<a href="mailto:charles@charlesism.com" class="">charles@charlesism.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">I'm with Matthew/Craig.<div class=""><br class=""></div><div class="">We discussed a couple very ternary-like versions earlier in the thread, which I increasingly think are the best options.</div><div class=""><br class=""></div><div class="">The major objection to this came from Lattner, and his objection, if I have it right, is "this proposal doesn't add enough functionality to justify the additional complexity/confusion"</div><div class=""><br class=""></div><div class="">The sticking point, at the moment, is formulating a really persuasive argument for "why we need this." If we can't do that, this proposal is dead.</div></div></div></blockquote><div><br class=""></div><div>I was originally hoping we could remove ternary and just make if and switch expressions. &nbsp;</div><div><br class=""></div><div>However, It seems to be clear that 1) there are enough challenges to making if and switch expressions that it won’t happen any time soon, if ever and 2) the conciseness of ternary is highly valued and it will be hard to beat it on conciseness.</div><div><br class=""></div><div>Given that, a ternary-like switch expression seems pretty valuable IMO. &nbsp;I think concrete examples showing how it helps to increase readability over: 1) switch statements and 2) immediately invoked closures are the best way to demonstrate the need for this feature.</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Tue, Dec 29, 2015 at 5:38 AM, Matthew Johnson via swift-evolution <span dir="ltr" class="">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt;</span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto" class=""><div class=""><br class=""><br class="">Sent from my iPad</div><span class=""><div class=""><br class="">On Dec 29, 2015, at 7:28 AM, Craig Cruden via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><br class=""></div><blockquote type="cite" class=""><div class="">That looks pretty ugly. &nbsp;<div class=""><br class=""></div><div class="">I think the best we can hope for at this point is maybe another keyword that mirrors switch but is expression based (aka match) — leaving the ternary ? : expression as is - which is not all that bad since any if else that becomes a compound expression or more than two resultant values (chaining) quickly becomes a mess. &nbsp;</div></div></blockquote><div class=""><br class=""></div></span><div class="">I agree that this is probably the best path forward at the moment.&nbsp; There was a post early on showing a ternary-like switch expression.&nbsp; I don't remember whether there were any specific problems with that idea or not, but if there aren't that might best route forward.</div><div class=""><div class="h5"><br class=""><blockquote type="cite" class=""><div class=""><div class=""><br class=""></div><div class="">I am not sure that even a “match” expression would be accepted at this point because there seems to be general resistance to anything more than the existing paradigm with a few functional decorations — and the way of doing things is good enough. &nbsp;</div><div class=""><br class=""></div><div class="">Concurrency is also currently off the table at this point -- the fact that immutable pure functional code can theoretically be parsed into a dependance graph which would allow for out of order [within scope] parallel execution on different threads [not sure if the overhead of doing so would outweigh the benefits]…. would also not be of sufficient benefit.&nbsp;</div><div class=""><br class=""></div><div class="">The primary focus of Swift is a language for UI development, not server development….</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><div class=""><blockquote type="cite" class=""><div class="">On 2015-12-29, at 15:07:57, James Campbell via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class=""><div class=""><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class="">What if you could wrap the existing switch statement in a closure and return a value from that closure like so</div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><br class=""></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class="">Let value = { switch (other) {</div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class="">Case .Some(let value):</div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class="">Return value // because this is in a closure the closure will return the value not the function this is in</div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class="">Case .None:</div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class="">Return "hello"&nbsp;</div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class="">}}</div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><br class=""></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><br class="">Sent from my iPhone</div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><br class="">On 29 Dec 2015, at 07:53, Howard Lovatt via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><br class=""></div><blockquote type="cite" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><div class=""><div class=""><div style="margin:0px;line-height:normal" class=""><font style="background-color:rgba(255,255,255,0)" class="">You can replace the proposed statement `which` (another thread), the existing statement `?:` (this thread), and the global function `??` (which is an odd ball) with matching library methods.</font></div><div style="margin:0px;line-height:normal" class=""><font style="background-color:rgba(255,255,255,0)" class=""><br class=""></font></div><div style="margin:0px;line-height:normal" class=""><font style="background-color:rgba(255,255,255,0)" class="">A library method is likely slower than a built in at this stage until the optimiser improves, but a library function:</font></div><div style="margin:0px;line-height:normal" class=""><font style="background-color:rgba(255,255,255,0)" class=""><br class=""></font></div><div style="margin:0px;line-height:normal" class=""><ol class=""><li class=""><font style="background-color:rgba(255,255,255,0)" class="">Is documented right in the IDE including code completion, statements aren’t (you don’t see quick help for `for`!)</font></li><li class=""><font style="background-color:rgba(255,255,255,0)" class="">Having a library function allows the use case to be throughly investigated. Is worth while as a language statement? What exact features are useful? EG should `which` support pattern matching, general boolean expressions, or simply be `Equatable` as shown below?</font></li><li class=""><font style="background-color:rgba(255,255,255,0)" class="">It is simpler to implement, maintain, and change a library function that a built-in.</font></li><li class=""><font style="background-color:rgba(255,255,255,0)" class="">There is no need for a keyword.</font></li></ol></div><div style="margin:0px;line-height:normal" class=""><font style="background-color:rgba(255,255,255,0)" class=""><br class=""></font></div><div style="margin:0px;line-height:normal" class=""><font style="background-color:rgba(255,255,255,0)" class="">First `which`:</font></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class=""><br class=""></span></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px" class=""><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">// Alternative to introducing `which` statement</span></div><div style="margin:0px;line-height:normal;min-height:13px" class=""><span style="background-color:rgba(255,255,255,0)" class=""><br class=""></span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">final</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class=""><span class="">class</span>&nbsp;Which&lt;I: Equatable, R&gt; {</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class=""><span class="">&nbsp; &nbsp;&nbsp;</span>private</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp; &nbsp;&nbsp;<span class="">var</span>&nbsp;result:&nbsp;<span class="">R</span>?</span></div><div style="margin: 0px; line-height: normal; min-height: 13px;" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp;&nbsp; &nbsp;</span><br class=""></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class=""><span class="">&nbsp; &nbsp;&nbsp;</span>private</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp; &nbsp;&nbsp;<span class="">let</span>&nbsp;which:&nbsp;<span class="">I</span></span></div><div style="margin: 0px; line-height: normal; min-height: 13px;" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp;&nbsp; &nbsp;</span><br class=""></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp; &nbsp;&nbsp;<span class="">init</span>(<span class="">_</span>&nbsp;which:&nbsp;<span class="">I</span>) {</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span class="">self</span>.<span class="">which</span>&nbsp;= which</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp; &nbsp; }</span></div><div style="margin: 0px; line-height: normal; min-height: 13px;" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp;&nbsp; &nbsp;</span><br class=""></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp; &nbsp;&nbsp;<span class="">func</span>&nbsp;match(value: I,&nbsp;<span class="">@noescape</span>&nbsp;matchResult: ()&nbsp;<span class="">throws</span>&nbsp;-&gt; R)&nbsp;<span class="">rethrows</span>&nbsp;-&gt;&nbsp;<span class="">Self</span>&nbsp;{</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span class="">if</span>&nbsp;<span class="">self</span>.<span class="">result</span>&nbsp;==&nbsp;<span class="">nil</span>&nbsp;&amp;&amp;&nbsp;<span class="">self</span>.<span class="">which</span>&nbsp;<span class="">==</span>&nbsp;value {</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span class="">self</span>.<span class="">result</span>&nbsp;=&nbsp;<span class="">try</span>&nbsp;matchResult()</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class=""><span class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span>return<span class="">&nbsp;</span>self</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp; &nbsp; }</span></div><div style="margin: 0px; line-height: normal; min-height: 13px;" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp;&nbsp; &nbsp;</span><br class=""></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp; &nbsp;&nbsp;<span class="">func</span>&nbsp;matchDefault(<span class="">@noescape</span>&nbsp;defaultResult: ()&nbsp;<span class="">throws</span>&nbsp;-&gt; R)&nbsp;<span class="">rethrows</span>&nbsp;-&gt;&nbsp;<span class="">R</span>&nbsp;{</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span class="">switch</span>&nbsp;<span class="">self</span>.<span class="">result</span>&nbsp;{</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span class="">case</span>&nbsp;.None:</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span class="">return</span>&nbsp;<span class="">try</span>&nbsp;defaultResult()</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span class="">case</span>&nbsp;.Some(<span class="">let</span>&nbsp;value):</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span class="">return</span>&nbsp;value</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp; &nbsp; }</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">}</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class=""><br class=""></span></div><div style="margin:0px;line-height:normal;min-height:13px" class=""><span style="background-color:rgba(255,255,255,0)" class=""><br class=""></span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">// Demo</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class=""><span class="">enum</span>&nbsp;Color {</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp; &nbsp;&nbsp;<span class="">case</span>&nbsp;Red, Blue, Green</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">}</span></div><div style="margin:0px;line-height:normal;min-height:13px" class=""><span style="background-color:rgba(255,255,255,0)" class=""><br class=""></span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">// Which with a default value</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class=""><span class="">let</span><span class="">&nbsp;i1 =&nbsp;</span><span class="">Which</span><span class="">(</span><span class="">Color</span><span class="">.</span><span class="">Red</span><span class="">)&nbsp;</span>// i =&nbsp;<a dir="ltr" href="tel:16711680" target="_blank" class="">16711680</a></span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp; &nbsp; .<span class="">match</span>(.<span class="">Red</span>) &nbsp; {&nbsp;<span class="">0xFF0000</span>&nbsp;}</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp; &nbsp; .<span class="">match</span>(.<span class="">Green</span>) {&nbsp;<span class="">0x00FF00</span>&nbsp;}</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp; &nbsp; .<span class="">match</span>(.<span class="">Blue</span>)&nbsp; {&nbsp;<span class="">0x00000FF</span>&nbsp;}</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class=""><span class="">&nbsp; &nbsp; .</span>matchDefault<span class="">&nbsp; {&nbsp;</span><span class="">0</span><span class="">&nbsp;}</span></span></div><div style="margin:0px;line-height:normal;min-height:13px" class=""><span style="background-color:rgba(255,255,255,0)" class=""><br class=""></span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">// Which that throws an error if it defaults</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class=""><span class="">let</span><span class="">&nbsp;i2:&nbsp;</span><span class="">Int</span><span class="">! =&nbsp;</span><span class="">Which</span><span class="">(</span><span class="">Color</span><span class="">.</span><span class="">Green</span><span class="">)&nbsp;</span>// i =&nbsp;<a dir="ltr" href="tel:16711680" target="_blank" class="">16711680</a></span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp; &nbsp; .<span class="">match</span>(.<span class="">Red</span>) &nbsp; {&nbsp;<span class="">0xFF0000</span>&nbsp;}</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp; &nbsp; .<span class="">match</span>(.<span class="">Green</span>) {&nbsp;<span class="">0x00FF00</span>&nbsp;}</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp; &nbsp; .<span class="">match</span>(.<span class="">Blue</span>)&nbsp; {&nbsp;<span class="">0x00000FF</span>&nbsp;}</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class=""><span class="">&nbsp; &nbsp; .</span><span class="">matchDefault</span><span class="">&nbsp; {&nbsp;</span><span class="">nil</span><span class="">&nbsp;}&nbsp;&nbsp;</span>// Cant type call to fatalError as no return, hence nil and type Int! (note !)</span></div></blockquote><font style="background-color:rgba(255,255,255,0)" class=""><div class=""><font style="background-color:rgba(255,255,255,0)" class=""><br class=""></font></div>Note runtime check for default rather than static check via compiler, not as good but not a big deal most of the time. The vast majority of languages don't do a compiler check on `switch`.</font></div><div class=""><font style="background-color:rgba(255,255,255,0)" class=""><br class="">Similarly the `?:` statement can be replaced:<br class=""><br class=""></font><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px" class=""><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">// Replacement for `?:` operator</span></div><div style="margin:0px;line-height:normal;min-height:13px" class=""><span style="background-color:rgba(255,255,255,0)" class=""><br class=""></span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class=""><span class="">struct</span>&nbsp;IfFalse&lt;R&gt; {</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class=""><span class="">&nbsp; &nbsp;&nbsp;</span>private</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp; &nbsp;&nbsp;<span class="">let</span>&nbsp;result:&nbsp;<span class="">R</span>?</span></div><div style="margin: 0px; line-height: normal; min-height: 13px;" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp;&nbsp; &nbsp;</span><br class=""></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp; &nbsp;&nbsp;<span class="">func</span>&nbsp;ifFalse(<span class="">@noescape</span>&nbsp;falseResult: ()&nbsp;<span class="">throws</span>&nbsp;-&gt; R)&nbsp;<span class="">rethrows</span>&nbsp;-&gt;&nbsp;<span class="">R</span>&nbsp;{</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span class="">switch</span>&nbsp;<span class="">self</span>.<span class="">result</span>&nbsp;{</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span class="">case</span>&nbsp;.None:</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span class="">return</span>&nbsp;<span class="">try</span>&nbsp;falseResult()</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span class="">case</span>&nbsp;.Some(<span class="">let</span>&nbsp;value):</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span class="">return</span>&nbsp;value</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp; &nbsp; }</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">}</span></div><div style="margin:0px;line-height:normal;min-height:13px" class=""><span style="background-color:rgba(255,255,255,0)" class=""><br class=""></span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">extension<span class="">&nbsp;</span><span class="">Bool</span><span class="">&nbsp;{</span></span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp; &nbsp;&nbsp;<span class="">func</span>&nbsp;ifTrue&lt;R&gt;(<span class="">@noescape</span>&nbsp;trueResult: ()&nbsp;<span class="">throws</span>&nbsp;-&gt; R)&nbsp;<span class="">rethrows</span>&nbsp;-&gt;&nbsp;<span class="">IfFalse</span>&lt;<span class="">R</span>&gt; {</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span class="">switch</span>&nbsp;<span class="">self</span>&nbsp;{</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span class="">case</span>&nbsp;<span class="">true</span>:</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span class="">return</span>&nbsp;<span class="">IfFalse</span>(result:&nbsp;<span class="">try</span>&nbsp;trueResult())</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span class="">case</span>&nbsp;<span class="">false</span>:</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span class="">return</span>&nbsp;<span class="">IfFalse</span>(result:&nbsp;<span class="">nil</span>)</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp; &nbsp; }</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">}</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class=""><br class=""></span></div><div style="margin:0px;line-height:normal;min-height:13px" class=""><span style="background-color:rgba(255,255,255,0)" class=""><br class=""></span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">// Demo</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class=""><span class="">let</span><span class="">&nbsp;sB =&nbsp;</span><span class="">true</span><span class="">.</span><span class="">ifTrue</span><span class="">{</span><span class="">"True"</span><span class="">}.</span><span class="">ifFalse</span><span class="">{</span><span class="">"False"</span><span class="">}&nbsp;</span>// "True" - for some reason needs {} and not () thinks () form throws</span></div></blockquote><font style="background-color:rgba(255,255,255,0)" class=""><br class=""></font><div style="margin:0px;line-height:normal" class=""><font style="background-color:rgba(255,255,255,0)" class="">Whilst the `??` operator is already a library function it is difficult to see in an expression, it gets&nbsp;buried, and is inconsistent in style because it is a non-mathematical operator and a symbol rather than a keyword or keyword followed by a symbol. The space either side of the `??` operator also makes it look like both arguments are of equal importance, whereas it is the left hand side that is important and the right hand side is just a catch.</font></div><font style="background-color:rgba(255,255,255,0)" class=""><br class=""></font><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px" class=""><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">// Replacement for `??` operator</span></div><div style="margin:0px;line-height:normal;min-height:13px" class=""><span style="background-color:rgba(255,255,255,0)" class=""><br class=""></span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">extension<span class="">&nbsp;</span><span class="">Optional</span><span class="">&nbsp;{</span></span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp; &nbsp;&nbsp;<span class="">func</span>&nbsp;ifNil(<span class="">@noescape</span>&nbsp;nilResult: ()&nbsp;<span class="">throws</span>&nbsp;-&gt; Wrapped)&nbsp;<span class="">rethrows</span>&nbsp;-&gt;&nbsp;<span class="">Wrapped</span>&nbsp;{</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span class="">switch</span>&nbsp;<span class="">self</span>&nbsp;{</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span class="">case</span>&nbsp;.None:</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span class="">return</span>&nbsp;<span class="">try</span>&nbsp;nilResult()</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span class="">case</span>&nbsp;.Some(<span class="">let</span>&nbsp;value):</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span class="">return</span>&nbsp;value</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">&nbsp; &nbsp; }</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">}</span></div><div style="margin:0px;line-height:normal;min-height:13px" class=""><span style="background-color:rgba(255,255,255,0)" class=""><br class=""></span></div><div style="margin:0px;line-height:normal;min-height:13px" class=""><span style="background-color:rgba(255,255,255,0)" class=""><br class=""></span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class="">// Demo</span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class=""><span class="">let</span>&nbsp;o:&nbsp;<span class="">String</span>? =&nbsp;<span class="">nil</span></span></div><div style="margin:0px;line-height:normal" class=""><span style="background-color:rgba(255,255,255,0)" class=""><span class="">let</span><span class="">&nbsp;sO =&nbsp;</span><span class="">o</span><span class="">.</span><span class="">ifNil</span><span class="">{</span><span class="">"Nil"</span><span class="">}&nbsp;</span>// "Nil" - for some reason needs {} and not () thinks () form throws</span></div></blockquote><font style="background-color:rgba(255,255,255,0)" class=""><br class=""></font><span class=""></span><br class="">Sent from my iPad</div><div class=""><br class="">On 29 Dec 2015, at 4:00 AM, Thorsten Seitz via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><br class=""></div><blockquote type="cite" class=""><div class=""><span class="">No exhaustiveness checking is a serious deficiency :-(</span><br class=""><span class=""></span><br class=""><span class="">-Thorsten</span><br class=""><span class=""></span><br class=""><blockquote type="cite" class=""><span class="">Am 17.12.2015 um 08:09 schrieb Brent Royal-Gordon via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt;:</span><br class=""></blockquote><blockquote type="cite" class=""><span class=""></span><br class=""></blockquote><blockquote type="cite" class=""><span class="">Actually, this *almost* does what you want. No @autoclosure for the values and no exhaustiveness checking, but otherwise...</span><br class=""></blockquote><span class="">_______________________________________________</span><br class=""><span class="">swift-evolution mailing list</span><br class=""><span class=""><a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a></span><br class=""><span class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br class=""></div></blockquote><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=xV0JY-2FdZMnUMvSFtZnLiBPRTDDOSQf3-2FpH33HYOlBxGuyq5t-2F3EGwb-2Fp-2FEknhUTetpoZ0Wf7T5ZvniexKcrPvo8tEDpvK-2BQtk9RzQpHso5fez-2BSQ2LDBkL9Ks5k8VGQKnbFrslKf-2FARG4G9z4e4A96v5QWrKAdGbpnbuQ8sMN5cXOOeeXx4a29EVMBG63w4wkj1yJ6CgFuVL-2FoAP9XmmlelXHKqzZkOxZtQ9xv5uowE-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0px!important;margin:0px!important;padding:0px!important" class=""></div></blockquote><blockquote type="cite" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><div class=""><span class="">_______________________________________________</span><br class=""><span class="">swift-evolution mailing list</span><br class=""><span class=""><a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a></span><br class=""><span class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br class=""></div></blockquote><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=CGU22LnxbYa2EM3wKvzuC6syQDwKa0tMs5IyT5gL1wK-2Ff2L-2FN-2B2Dw8ua-2B-2Fgt1whboccNv1eVX1m5F4BIFzMEI3GyIOUp2iAHIgKUzzY1eu0AzRTVU2AoOo79z6YmO6u1qsqgdTknQ3Xi1P5E4xQiuF8cYxHRj4NuBSxFoBfDhDwJZmP-2BMJWbW215qjimsdGEEZo84d0DmRYDrJgoYaRt3qkfARPzEvbKj6UUZkfGyhc-3D" alt="" width="1" height="1" border="0" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;min-height:1px!important;width:1px!important;border-width:0px!important;margin:0px!important;padding:0px!important" class=""><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important" class=""><span class="">&nbsp;</span>_______________________________________________</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important" class="">swift-evolution mailing list</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><a href="mailto:swift-evolution@swift.org" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank" class="">swift-evolution@swift.org</a><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div><br class=""></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=eLFMrKDT8iBxZ-2Fbnk-2BZqvSchNN-2FvYXdceA0T7VxwkAfkb833H-2FjwKnSroOp8KiGVuDGbW-2Fwy4uhqQB7om5k0KTYlkv0aLaQh3LtCBTpQGIAkonBeHlOcarih2Dn07sGJPAMVXZC2kW-2BdiaZTSIkJt2oORTsvoiZzH4OQNnHLzu-2F826VcGbJJXmjyjXS5ZGY7dQpYGr3e8V7ACfJZw-2BIRns4VMtGGFC-2BPTHsqiQJhkrE-3D" alt="" width="1" height="1" border="0" style="min-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></blockquote><blockquote type="cite" class=""><div class=""><span class="">_______________________________________________</span><br class=""><span class="">swift-evolution mailing list</span><br class=""><span class=""><a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a></span><br class=""><span class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br class=""></div></blockquote>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=l3fs1g-2F466j3y5fD5Q61KddsTTCmXL0uxw3XoAMFFNjeswZ2QsLAA7lo-2BqPpRbTLjoJ82rvt2v-2Bn87lR6aYeNz60ONUxs7QNBYb0HW886jvPrtFmi0GJSdhcZA5xtT5ospyqZAKc9v-2BOB1hjYU1hRol-2BhovdQI9kxKyGcqW5OiBc1-2BVOxa3FAGhSQ-2BE7gUiaddAO7DLbbLWyI38yRrt0QSAE7nvBGuNlucBQM-2FViNyE-3D" alt="" width="1" height="1" border="0" style="min-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></div></div>
<br class="">_______________________________________________<br class="">
swift-evolution mailing list<br class="">
<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">
<br class=""></blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></body></html>