<div dir="ltr"><div>-1 on </div><div><br></div><pre class="gmail_msg" style="color:rgb(51,51,51);box-sizing:border-box;font-family:consolas,&#39;liberation mono&#39;,menlo,courier,monospace;font-size:13.600000381469727px;margin-top:0px;margin-bottom:0px;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(247,247,247);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-break:normal"><span class="inbox-m_6922547719217291137pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">if</span> unwrap myValue { <span class="inbox-m_6922547719217291137pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">...</span> }</pre><div class="gmail_quote"><div dir="ltr"><br></div><div>In my opinion, <b>shadowing names is an anti-pattern,</b> so making it easier isn&#39;t something we should encourage. Detailed examples, shall you wish, are below.<br></div><div><br></div><div>Consider a developer who is suddenly able to change all employment relationships in the company. </div><div>He&#39;s happily coding a function that should guarantee him a boss-free lifestyle:</div><div><br></div><div><div class="gmail_msg"><font face="monospace, monospace" class="gmail_msg">class Employee {</font></div><div class="gmail_msg"><font face="monospace, monospace" class="gmail_msg">    var currentSupervisor: Employee?</font></div><div class="gmail_msg"><br></div><div class="gmail_msg"><font face="monospace, monospace" class="gmail_msg">    // Precondition: you can do whatever you want :)</font></div><div class="gmail_msg"><font face="monospace, monospace" class="gmail_msg">    // Requirements: currentSupervisor == nil at the end</font></div><div class="gmail_msg"><font face="monospace, monospace" class="gmail_msg">    func fireYourBoss() {</font></div><div class="gmail_msg"><font face="monospace, monospace" class="gmail_msg">        if unwrap currentSupervisor {</font></div><div class="gmail_msg"><font face="monospace, monospace" class="gmail_msg">            company.goToMeeting() // &lt;- anything can happen on a meeting</font></div><div class="gmail_msg"><font face="monospace, monospace" class="gmail_msg">            company.fire(currentSupervisor) // &lt;- firing a manager nullifies the supervisor relationship</font></div><div class="gmail_msg"><font face="monospace, monospace" class="gmail_msg">            // Now I definitely have currentSupervisor == nil... or do I?</font></div><div class="gmail_msg"><span style="font-family:monospace,monospace">        }</span><br></div><div class="gmail_msg"><font face="monospace, monospace" class="gmail_msg">    }</font></div><div class="gmail_msg"><font face="monospace, monospace" class="gmail_msg">}</font></div></div><div dir="ltr"><br></div><div>This code contains a design problem: the local variable bound to <span style="font-family:monospace,monospace">currentSupervisor</span> name shadows the instance property with the same name. The unwrap operator guarantees that the values bound to those names are equal in the beginning of the then-block; however, there is no reason to think that this will hold after <span style="font-family:monospace,monospace">company.goToMeeting()</span>.</div><div><br></div><div>Compare this to how this code will read without the shadowing:</div><div><br></div><div><div><div class="gmail_msg"><span style="font-family:monospace,monospace">        if let bad_boss = currentSupervisor {</span><br></div><div class="gmail_msg"><font face="monospace, monospace" class="gmail_msg">            company.goToMeeting()</font></div><div class="gmail_msg"><font face="monospace, monospace" class="gmail_msg">            company.fire(bad_boss)</font></div><div class="gmail_msg"><font face="monospace, monospace" class="gmail_msg">        }</font></div><div class="gmail_msg"><br></div><div class="gmail_msg">It is much clearer in this case what happens – the person being fired is the old value of <span style="font-family:monospace,monospace">currentSupervisor. </span>Since the problem is now clearly diagnozed, the code can now be improved to guarantee the blissful future, for example as follows</div></div></div><div class="gmail_msg"><br></div><div class="gmail_msg"><div class="gmail_msg"><span style="font-family:monospace,monospace">        if let bad_boss = currentSupervisor {</span><br></div><div class="gmail_msg"><font face="monospace, monospace" class="gmail_msg">            company.goToMeeting()</font></div><div class="gmail_msg"><font face="monospace, monospace" class="gmail_msg">            if let another_boss = currentSupervisor {</font></div><div class="gmail_msg"><font face="monospace, monospace" class="gmail_msg">                company.fire(another_boss) </font></div><div class="gmail_msg"><font face="monospace, monospace" class="gmail_msg">            }</font></div><div class="gmail_msg"><font face="monospace, monospace" class="gmail_msg">        }</font></div><div><br></div></div><div>Similarly, in general, shadowing is a big source of bugs and should be avoided in all cases where the shadowed and shadowing variable&#39;s values can be different. </div><div><br></div><div>In multithreaded programs it&#39;s basically only safe to shadow those names that are bound with let, so we could implement unwrap for those, but it&#39;s unclear what the big benefits of it are.</div><div><br></div><div>Thanks for reading up to here, </div><div>Ilya.</div><div><br></div><div dir="ltr">On Tue, Nov 1, 2016 at 9:28 PM Nevin Brackett-Rozinsky via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg">Bikeshedding here—is there any way we can make it look like this for enums?<div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><font face="monospace, monospace" class="gmail_msg">if let str = unwrap json.string {</font></div><div class="gmail_msg"><font face="monospace, monospace" class="gmail_msg">    // str is the value from the .string enum case</font></div><div class="gmail_msg"><font face="monospace, monospace" class="gmail_msg">}</font></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Essentially, the “unwrap” keyword would treat the last “path component” of what follows as an enum case, and extract the associated value if it matches.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">This could even work with tuple destructuring, as in:</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><div class="gmail_msg"><font face="monospace, monospace" class="gmail_msg">guard let (theCode, someMessage) = unwrap myResponse.contact else {</font></div><div class="gmail_msg"><font face="monospace, monospace" class="gmail_msg">    return</font></div><div class="gmail_msg"><font face="monospace, monospace" class="gmail_msg">}</font></div></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">And of course we could add a sugared form for optionals to allow the simple, “<font face="monospace, monospace" class="gmail_msg">if unwrap x { … }</font>”.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">I’m not sure if this is where we want to take the idea, it’s just something I thought of.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">If we did go that route, then we might need to disallow enums from having properties with the same names as their cases (otherwise, eg. json.string would refer to a property not a case).</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">On the other hand, a slightly different syntax would avoid that issue entirely—for instance,</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><font face="monospace, monospace" class="gmail_msg">if let str = unwrap json(.string) { … }</font></div><div class="gmail_msg">or</div><div class="gmail_msg"><font face="monospace, monospace" class="gmail_msg">if let str = unwrap</font><span style="font-family:monospace,monospace" class="gmail_msg">(.string)</span><font face="monospace, monospace" class="gmail_msg"> json { … }</font></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">That last one could even be sugared further when shadowing is desired:</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><div class="gmail_msg"><font face="monospace, monospace" class="gmail_msg">if unwrap</font><span style="font-family:monospace,monospace" class="gmail_msg">(.string)</span><font face="monospace, monospace" class="gmail_msg"> json {</font></div><div class="gmail_msg"><font face="monospace, monospace" class="gmail_msg">    // json is a String in here</font></div><div class="gmail_msg"><font face="monospace, monospace" class="gmail_msg">}</font></div></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Potentially worthwhile?<br class="gmail_msg"></div></div><div dir="ltr" class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Nevin</div></div><div dir="ltr" class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_extra gmail_msg"><br class="gmail_msg"><div class="gmail_quote gmail_msg">On Tue, Nov 1, 2016 at 2:42 PM, Erica Sadun via swift-evolution <span dir="ltr" class="gmail_msg">&lt;<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br class="gmail_msg"><blockquote class="gmail_quote gmail_msg" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word" class="gmail_msg">With massive revisions. I&#39;ve added Xiaodi Wu to author list. I&#39;ve combined all unwrapping together. I&#39;ve added a much more sensible approach (plus a bluesky one) for real world enumerations.<div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Gist with live updates here: <a href="https://gist.github.com/erica/db9ce92b3d23cb20799460f603c0ae7c" class="gmail_msg" target="_blank">https://gist.github.com/erica/db9ce92b3d23cb20799460f603c0ae7c</a></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Send feedback, I will continue to revise.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">-- E</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><h1 style="box-sizing:border-box;margin:0px 0px 16px;line-height:1.25;padding-bottom:0.3em;border-bottom:1px solid rgb(238,238,238);color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;background-color:rgb(255,255,255)" class="gmail_msg">Better Unwrapping</h1><ul style="box-sizing:border-box;padding-left:2em;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg"><li style="box-sizing:border-box" class="gmail_msg">Proposal: TBD</li><li style="box-sizing:border-box;margin-top:0.25em" class="gmail_msg">Author: <a href="https://github.com/erica" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none" class="gmail_msg" target="_blank">Erica Sadun</a>, <a href="https://github.com/lattner" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none" class="gmail_msg" target="_blank">Chris Lattner</a>, <a href="https://github.com/xwu" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none" class="gmail_msg" target="_blank">Xiaodi Wu</a> David Goodine</li><span class="m_-4588606749269976813gmail- gmail_msg"><li style="box-sizing:border-box;margin-top:0.25em" class="gmail_msg">Status: TBD</li><li style="box-sizing:border-box;margin-top:0.25em" class="gmail_msg">Review manager: TBD</li></span></ul><h2 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom:1px solid rgb(238,238,238);color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;background-color:rgb(255,255,255)" class="gmail_msg"><a id="m_-4588606749269976813gmail-m_7548809065351022967user-content-introduction" class="m_-4588606749269976813gmail-m_7548809065351022967anchor gmail_msg" href="https://gist.github.com/erica/db9ce92b3d23cb20799460f603c0ae7c#introduction" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none;float:left;padding-right:4px;line-height:1" target="_blank"><u class="gmail_msg"></u><u class="gmail_msg"></u><u class="gmail_msg"></u><u class="gmail_msg"></u></a>Introduction</h2><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">This proposal redesigns common unwrapping tasks:</p><ul style="box-sizing:border-box;padding-left:2em;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg"><li style="box-sizing:border-box" class="gmail_msg">It introduces the <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">unwrap</code> keyword for optional values</li><li style="box-sizing:border-box;margin-top:0.25em" class="gmail_msg">It re-architects <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">guard case</code> and <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">if case</code> grammar to support unwrapping more complex enumerations by dropping the <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">case</code> keyword and replacing <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">=</code> with <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">~=</code>.</li><li style="box-sizing:border-box;margin-top:0.25em" class="gmail_msg">It applies <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">unwrap</code> to non-optional values</li></ul><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">Swift Evolution threads:</p><ul style="box-sizing:border-box;padding-left:2em;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg"><span class="m_-4588606749269976813gmail- gmail_msg"><li style="box-sizing:border-box" class="gmail_msg"><a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20161024/028440.html" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none" class="gmail_msg" target="_blank">guard let x = x</a></li></span><li style="box-sizing:border-box;margin-top:0.25em" class="gmail_msg"><a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160201/thread.html" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none" class="gmail_msg" target="_blank">Using a <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">bind</code> keyword</a>.</li><li style="box-sizing:border-box;margin-top:0.25em" class="gmail_msg"><a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20161024/tbd.html" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none" class="gmail_msg" target="_blank">Fixing pattern matching grammar</a></li></ul><h2 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom:1px solid rgb(238,238,238);color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;background-color:rgb(255,255,255)" class="gmail_msg"><a id="m_-4588606749269976813gmail-m_7548809065351022967user-content-motivation" class="m_-4588606749269976813gmail-m_7548809065351022967anchor gmail_msg" href="https://gist.github.com/erica/db9ce92b3d23cb20799460f603c0ae7c#motivation" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none;float:left;padding-right:4px;line-height:1" target="_blank"><u class="gmail_msg"></u><u class="gmail_msg"></u><u class="gmail_msg"></u><u class="gmail_msg"></u></a>Motivation</h2><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">Unwrapping values is one of the most common Swift tasks and it is unnecessarily complex. This proposal simplifies this process and enhances code safety and readability.</p><h3 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;font-size:1.25em;line-height:1.25;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;background-color:rgb(255,255,255)" class="gmail_msg"><a id="m_-4588606749269976813gmail-m_7548809065351022967user-content-optionals" class="m_-4588606749269976813gmail-m_7548809065351022967anchor gmail_msg" href="https://gist.github.com/erica/db9ce92b3d23cb20799460f603c0ae7c#optionals" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none;float:left;padding-right:4px;line-height:1" target="_blank"><u class="gmail_msg"></u><u class="gmail_msg"></u><u class="gmail_msg"></u><u class="gmail_msg"></u></a>Optionals</h3><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">Swift lacks a safe way to bind an optional to a shadowed same-name variable in condition clauses like those used in <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">guard</code> and <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">if</code> statements.</p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">Compare:</p><div class="m_-4588606749269976813gmail-m_7548809065351022967highlight m_-4588606749269976813gmail-m_7548809065351022967highlight-source-swift gmail_msg" style="box-sizing:border-box;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;background-color:rgb(255,255,255)"><pre style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(247,247,247);border-radius:3px;word-break:normal" class="gmail_msg"><span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">guard</span> <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> foo <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">=</span> foo <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">else</span> { <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">...</span> } <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)">// redundant</span>
<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span><span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">guard</span> <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> .<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">some</span>(foo) <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">=</span> foo <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">else</span> { <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">...</span> } <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)">// overly complex</span>
<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span>
<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">guard</span> unwrap foo <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">else</span> { <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">...</span> } <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)">// simple</span></pre></div><ul style="box-sizing:border-box;padding-left:2em;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg"><li style="box-sizing:border-box" class="gmail_msg">Using &quot;foo = foo&quot; fails <a href="https://en.wikipedia.org/wiki/Don%27t_repeat_yourself" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none" class="gmail_msg" target="_blank">DRY principles</a>. </li><li style="box-sizing:border-box;margin-top:0.25em" class="gmail_msg">Using <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">case let .some(foo) = foo</code> or <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">case .some(let foo) = foo</code> fails <a href="https://en.wikipedia.org/wiki/KISS_principle" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none" class="gmail_msg" target="_blank">KISS principles</a></li></ul><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg"><code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">unwrap</code> guarantees that an unwrapped shadow uses the same name as the wrapped version. This ensures that a conditionally-bound item cannot accidentally shadow another symbol. It eliminates repetition and retains clarity. Further, the <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">unwrap</code> keyword is common, simple to understand, and easy to search for if Swift users are unfamiliar with it.</p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">In the rare case that the binding is variable, use the re-imagined <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">var ~=</code> syntax</p><h3 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;font-size:1.25em;line-height:1.25;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;background-color:rgb(255,255,255)" class="gmail_msg"><a id="m_-4588606749269976813gmail-m_7548809065351022967user-content-general-enumerations" class="m_-4588606749269976813gmail-m_7548809065351022967anchor gmail_msg" href="https://gist.github.com/erica/db9ce92b3d23cb20799460f603c0ae7c#general-enumerations" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none;float:left;padding-right:4px;line-height:1" target="_blank"><u class="gmail_msg"></u><u class="gmail_msg"></u><u class="gmail_msg"></u><u class="gmail_msg"></u></a>General Enumerations</h3><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">Swift&#39;s <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">guard case</code> and <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">if case</code> statements stand out for their unintuitive approach. They look like assignment statements but they are <em style="box-sizing:border-box" class="gmail_msg">not</em> assignment statements. This violates the <a href="https://en.wikipedia.org/wiki/Principle_of_least_astonishment" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none" class="gmail_msg" target="_blank">principle of least astonishment</a>. This presents difficulties for new language adopters by combining several concepts in a confusing form. They are arguably underutilized by language experts.</p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">The status quo for the <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">=</code> operator is iteratively built up in this fashion:</p><ul style="box-sizing:border-box;padding-left:2em;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg"><li style="box-sizing:border-box" class="gmail_msg"><code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">=</code> performs assignment</li><li style="box-sizing:border-box;margin-top:0.25em" class="gmail_msg"><code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">let x =</code> performs binding</li><li style="box-sizing:border-box;margin-top:0.25em" class="gmail_msg"><code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">if let x =</code> performs conditional binding on optionals</li><li style="box-sizing:border-box;margin-top:0.25em" class="gmail_msg"><code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">if case .foo(let x) =</code> and <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">if case let .foo(x) =</code> performs conditional binding on enumerations <em style="box-sizing:border-box" class="gmail_msg">and</em> applies pattern matching</li></ul><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">Both <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">guard case</code> and <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">if case</code> statements perform simultaneous pattern matching and conditional binding. Here are examples demonstrating their use in current Swift:</p><pre style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:16px;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(247,247,247);border-radius:3px;color:rgb(51,51,51)" class="gmail_msg"><code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;padding:0px;margin:0px;background-color:transparent;border-radius:3px;word-break:normal;border:0px;display:inline;overflow:visible;line-height:inherit;word-wrap:normal" class="gmail_msg">enum Result&lt;T&gt; { case success(T), error(Error) }

// valid Swift
guard case let .success(value) = result
    else { ... }

// valid Swift
guard case .success(let value) = result
    else { ... }
</code></pre><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">The problems with <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">guard case</code> and <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">if case</code> include:</p><ul style="box-sizing:border-box;padding-left:2em;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg"><li style="box-sizing:border-box" class="gmail_msg">The <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">=</code> operator looks like assignment and not like pattern matching (<code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">~=</code>). </li><li style="box-sizing:border-box;margin-top:0.25em" class="gmail_msg">The <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">case</code> layout is both too close to a <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">switch</code>&#39;s <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">case</code> but doesn&#39;t follow its syntax. In <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">switch</code>, a <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">case</code> is followed by a colon, not an equal sign.</li><li style="box-sizing:border-box;margin-top:0.25em" class="gmail_msg">Using the <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">case</code> syntax is unneccessarily wordy. It incorporates <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">case</code>, <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">=</code>, and optionally <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">let</code>/<code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">var</code> assignments.</li></ul><h3 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;font-size:1.25em;line-height:1.25;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;background-color:rgb(255,255,255)" class="gmail_msg"><a id="m_-4588606749269976813gmail-m_7548809065351022967user-content-indirect-and-direct-pattern-matching" class="m_-4588606749269976813gmail-m_7548809065351022967anchor gmail_msg" href="https://gist.github.com/erica/db9ce92b3d23cb20799460f603c0ae7c#indirect-and-direct-pattern-matching" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none;float:left;padding-right:4px;line-height:1" target="_blank"><u class="gmail_msg"></u><u class="gmail_msg"></u><u class="gmail_msg"></u><u class="gmail_msg"></u></a>Indirect and Direct Pattern Matching</h3><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">Swift uses two kinds of pattern matching.</p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg"><span style="box-sizing:border-box;font-weight:600" class="gmail_msg">Indirect pattern matching</span> such as the kind you see in <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">switch</code> and <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">for</code> statements receives an argument in from the statement structure. The argument is not mentioned directly in the <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">case</code>:</p><pre style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:16px;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(247,247,247);border-radius:3px;color:rgb(51,51,51)" class="gmail_msg"><code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;padding:0px;margin:0px;background-color:transparent;border-radius:3px;word-break:normal;border:0px;display:inline;overflow:visible;line-height:inherit;word-wrap:normal" class="gmail_msg">switch value {
case .foo(let x): ... use x ...
...
}

for case .foo(let x) in collection { ... }
</code></pre><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg"><span style="box-sizing:border-box;font-weight:600" class="gmail_msg">Direct pattern matching</span> including <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">guard</code>/<code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">if</code> statements and with the pattern matching operator place the argument to be matched to the right of an operator, either <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">=</code> or <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">~=</code>. The argument is explicitly mentioned:</p><pre style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:16px;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(247,247,247);border-radius:3px;color:rgb(51,51,51)" class="gmail_msg"><code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;padding:0px;margin:0px;background-color:transparent;border-radius:3px;word-break:normal;border:0px;display:inline;overflow:visible;line-height:inherit;word-wrap:normal" class="gmail_msg">if case .foo(let x) = value { ... use x ... }
if 100...200 ~= value { ... }
</code></pre><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">When using <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">if case</code>/<code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">guard case</code> in the absence of conditional binding, statements duplicate basic pattern matching with less obvious semantics. These following two statements are functionally identical. The second uses an assignment operator and the <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">case</code> keyword.</p><pre style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:16px;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(247,247,247);border-radius:3px;color:rgb(51,51,51)" class="gmail_msg"><code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;padding:0px;margin:0px;background-color:transparent;border-radius:3px;word-break:normal;border:0px;display:inline;overflow:visible;line-height:inherit;word-wrap:normal" class="gmail_msg">if range ~= myValue { ... } // simpler
if case range = myValue { ... } // confusing
</code></pre><h2 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom:1px solid rgb(238,238,238);color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;background-color:rgb(255,255,255)" class="gmail_msg"><a id="m_-4588606749269976813gmail-m_7548809065351022967user-content-detailed-design" class="m_-4588606749269976813gmail-m_7548809065351022967anchor gmail_msg" href="https://gist.github.com/erica/db9ce92b3d23cb20799460f603c0ae7c#detailed-design" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none;float:left;padding-right:4px;line-height:1" target="_blank"><u class="gmail_msg"></u><u class="gmail_msg"></u><u class="gmail_msg"></u><u class="gmail_msg"></u></a>Detailed Design</h2><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">This proposal introduces the <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">unwrap</code> keyword. The <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">unwrap</code> statement shadows an enumeration variable to an unwrapped version of the same type. Upon adopting this proposal the following statements produce equivalent behvior:</p><div class="m_-4588606749269976813gmail-m_7548809065351022967highlight m_-4588606749269976813gmail-m_7548809065351022967highlight-source-swift gmail_msg" style="box-sizing:border-box;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;background-color:rgb(255,255,255)"><pre style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(247,247,247);border-radius:3px;word-break:normal" class="gmail_msg"><span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)">// New unwrap keyword</span>
<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span><span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">if</span> unwrap myValue { <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">...</span> }

<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)">// Existing same-name shadowing</span>
<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span><span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">if</span> <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> myValue <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">=</span> myValue { <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">...</span> }

<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)">// Existing same-name pattern matching and conditional binding</span>
<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span><span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">if</span> <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> .<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">some</span>(<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> myValue) <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">=</span> myValue { <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">...</span> } <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)">// old grammar</span>
<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span><span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">if</span> <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> .<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">some</span>(myValue) <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">=</span> myValue { <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">...</span> } <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)">// old grammar</span>
<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span>
<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)">// Proposed same-name pattern matching and conditional binding</span>
<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span><span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">if</span> .<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">some</span>(<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> myValue) <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">~=</span> myValue { <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">...</span> } <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)">// new grammar</span>
<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span><span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">if</span> <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> .<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">some</span>(myValue) <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">~=</span> myValue { <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">...</span> } <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)">// new grammar</span></pre></div><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">In <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">if case</code> and <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">guard case</code>, this proposal drops the <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">case</code> keyword and replaces the equal sign with the pattern matching operator. The results look like this:</p><div class="m_-4588606749269976813gmail-m_7548809065351022967highlight m_-4588606749269976813gmail-m_7548809065351022967highlight-source-swift gmail_msg" style="box-sizing:border-box;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;background-color:rgb(255,255,255)"><pre style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(247,247,247);border-radius:3px;word-break:normal" class="gmail_msg"><span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">guard</span> <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> .<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">success</span>(value) <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">~=</span> result <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">else</span> { <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">...</span> }
<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">guard</span> .<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">success</span>(<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> value) <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">~=</span> result <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">else</span> { <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">...</span> }
<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">if</span> <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> .<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">success</span>(value) <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">~=</span> result { <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">...</span> }
<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">if</span> .<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">success</span>(<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> value) <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">~=</span> result { <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">...</span> }
<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">guard</span> <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> x<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">?</span> <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">~=</span> anOptional <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">else</span> { <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">...</span> }
<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">if</span> <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> x<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">?</span> <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">~=</span> anOptional { <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">...</span> }</pre></div><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">Users may choose to use <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">var</code> instead of <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">let</code> to bind to a variable instead of a constant. </p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">In this update:</p><ul style="box-sizing:border-box;padding-left:2em;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg"><li style="box-sizing:border-box" class="gmail_msg">The <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">case</code> keyword is subsumed into the (existing) pattern matching operator</li><li style="box-sizing:border-box;margin-top:0.25em" class="gmail_msg">The statements adopt the existing <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">if-let</code> and <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">guard-let</code> syntax, including <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">Optional</code> syntactic sugar.</li></ul><div class="m_-4588606749269976813gmail-m_7548809065351022967highlight m_-4588606749269976813gmail-m_7548809065351022967highlight-source-swift gmail_msg" style="box-sizing:border-box;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;background-color:rgb(255,255,255)"><pre style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(247,247,247);border-radius:3px;word-break:normal" class="gmail_msg"><span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">if</span> <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> x <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">=</span> anOptional { <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">...</span> } <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)">// current</span>
<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span><span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">if</span> <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> x<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">?</span> <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">=</span> anOptional { <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">...</span> } <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)">// current, would be removed</span>
<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span>
<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">if</span> <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> x<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">?</span> <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">~=</span> anOptional { <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">...</span> } <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)">// proposed replacement for `if case`</span></pre></div><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">On adopting this syntax, the two identical range tests naturally unify to this single version:</p><div class="m_-4588606749269976813gmail-m_7548809065351022967highlight m_-4588606749269976813gmail-m_7548809065351022967highlight-source-swift gmail_msg" style="box-sizing:border-box;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;background-color:rgb(255,255,255)"><pre style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(247,247,247);border-radius:3px;word-break:normal" class="gmail_msg"><span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">if</span> range <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">~=</span> myValue { <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">...</span> } <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)">// before</span>
<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span><span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">if</span> <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> range <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">=</span> myValue { <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">...</span> } <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)">// before</span>
<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span>
<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">if</span> range <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">~=</span> myValue { <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">...</span> } <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)">// after</span></pre></div><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">Using pattern matching without conditional binding naturally simplifies to a standalone Boolean condition clause.</p><h3 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;font-size:1.25em;line-height:1.25;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;background-color:rgb(255,255,255)" class="gmail_msg"><a id="m_-4588606749269976813gmail-m_7548809065351022967user-content-unwrap-and-non-optionals" class="m_-4588606749269976813gmail-m_7548809065351022967anchor gmail_msg" href="https://gist.github.com/erica/db9ce92b3d23cb20799460f603c0ae7c#unwrap-and-non-optionals" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none;float:left;padding-right:4px;line-height:1" target="_blank"><u class="gmail_msg"></u><u class="gmail_msg"></u><u class="gmail_msg"></u><u class="gmail_msg"></u></a><code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:inherit;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">unwrap</code> and Non-Optionals</h3><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">Real world Swift enumerations rarely follow the Optional pattern, which can be summed up like this:</p><div class="m_-4588606749269976813gmail-m_7548809065351022967highlight m_-4588606749269976813gmail-m_7548809065351022967highlight-source-swift gmail_msg" style="box-sizing:border-box;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;background-color:rgb(255,255,255)"><pre style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(247,247,247);border-radius:3px;word-break:normal" class="gmail_msg"><span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">enum</span> <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">OptionalLike</span>&lt;<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-v gmail_msg" style="box-sizing:border-box;color:rgb(237,106,67)">T</span>&gt; { <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">aCaseWithOneAssociatedValue</span>(T), <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">anotherCase</span> }</pre></div><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">They more typically look like this:</p><div class="m_-4588606749269976813gmail-m_7548809065351022967highlight m_-4588606749269976813gmail-m_7548809065351022967highlight-source-swift gmail_msg" style="box-sizing:border-box;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;background-color:rgb(255,255,255)"><pre style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(247,247,247);border-radius:3px;word-break:normal" class="gmail_msg"><span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)">// One generic, one known type</span>
<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span><span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">enum</span> <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">Result</span>&lt;<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-v gmail_msg" style="box-sizing:border-box;color:rgb(237,106,67)">Value</span>&gt; { <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">success</span>(<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">Value</span>), <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">failure</span>(<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">Error</span>) }

<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)">// Many cases of mixed types</span>
<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span><span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">enum</span> <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">JSON</span> {
    <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">string</span>(<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">String</span>)
    <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">number</span>(<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">Double</span>)
    <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">boolean</span>(<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">Bool</span>)
    <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">array</span>([JSON])
    <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">dictionary</span>([<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">String</span>: JSON])
    <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">null</span>
}

<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)">// Multiple associated values</span>
<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span><span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">enum</span> <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">Response</span> { <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">contact</span>(<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)"><span class="m_-4588606749269976813gmail-m_7548809065351022967pl-smi gmail_msg" style="box-sizing:border-box;color:rgb(51,51,51)">code</span></span>: <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">Int</span>, <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)"><span class="m_-4588606749269976813gmail-m_7548809065351022967pl-smi gmail_msg" style="box-sizing:border-box;color:rgb(51,51,51)">message</span></span>: <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">String</span>), <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">failure</span> }</pre></div><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">You can adapt the <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">bind</code> keyword to work with these real-world cases in one of two ways. The first way uses <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">unwrap</code>instead of <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">let</code> or <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">var</code>. Here are a few varieties of how that call might look versus the proposed update for normal pattern matching:</p><div class="m_-4588606749269976813gmail-m_7548809065351022967highlight m_-4588606749269976813gmail-m_7548809065351022967highlight-source-swift gmail_msg" style="box-sizing:border-box;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;background-color:rgb(255,255,255)"><pre style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(247,247,247);border-radius:3px;word-break:normal" class="gmail_msg"><span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">if</span> unwrap .<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">string</span>(myString) <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">~=</span> json { <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">...</span> }
<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">if</span> unwrap .<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">contact</span>(code, <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">_</span>) <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">~=</span> response { <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">...</span> }
<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">if</span> unwrap .<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">contact</span>(code, <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">var</span> message) <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">~=</span> response { <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">...</span> }

<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)">// vs proposed</span>
<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span>
<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">if</span> <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> .<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">string</span>(myString) <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">~=</span> json { <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">...</span> }
<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">if</span> <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">var</span> .<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">string</span>(myString) <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">~=</span> json { <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">...</span> }
<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">if</span> .<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">contact</span>(<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> code, <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">_</span>) <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">~=</span> response { <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">...</span> }
<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">if</span> .<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">contact</span>(<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> code, <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">var</span> message) <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">~=</span> response { <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">...</span> }</pre></div><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">Although slightly wordier than <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">let</code> and <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">var</code>, the <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">unwrap</code> solution offers advantages:</p><ul style="box-sizing:border-box;padding-left:2em;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg"><li style="box-sizing:border-box" class="gmail_msg">It enhances readability. If the goal is to unwrap an embedded value, <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">unwrap</code> uses a more appropriate term.</li><li style="box-sizing:border-box;margin-top:0.25em" class="gmail_msg">It establishes <em style="box-sizing:border-box" class="gmail_msg">one</em> place for the keyword to live instead of the &quot;does it go inside or outside&quot; status quo. A consistent place means prettier code.</li><li style="box-sizing:border-box;margin-top:0.25em" class="gmail_msg">As shown in these examples, it can easily be adapted for variable binding. If you want to override the let behavior, you can insert a var inside the parentheses.</li></ul><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">A second, riskier, cleaner approach looks like this. It assumes the compiler can pick up and shadow using either the associated value labels (preferred) or the enumeration name (as you&#39;d see with <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">String</code> raw value enumerations):</p><div class="m_-4588606749269976813gmail-m_7548809065351022967highlight m_-4588606749269976813gmail-m_7548809065351022967highlight-source-swift gmail_msg" style="box-sizing:border-box;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;background-color:rgb(255,255,255)"><pre style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(247,247,247);border-radius:3px;word-break:normal" class="gmail_msg"><span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">if</span> unwrap .<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-smi gmail_msg" style="box-sizing:border-box">contact</span> <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">~=</span> response { 
   <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">...</span> some compiler magic picks up on the `code` and `message` labels
   used <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">for</span> initialization, so the bound variables are `code`
   and `message`
}

<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">if</span> unwrap .<span class="m_-4588606749269976813gmail-m_7548809065351022967pl-smi gmail_msg" style="box-sizing:border-box">string</span> <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">~=</span> json { 
   <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">...</span> use `string` <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">here</span> (same name <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">as</span> <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">enum</span> <span class="m_-4588606749269976813gmail-m_7548809065351022967pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">case</span>) because
   no label was used to define the associated value
}</pre></div><h2 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom:1px solid rgb(238,238,238);color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;background-color:rgb(255,255,255)" class="gmail_msg"><a id="m_-4588606749269976813gmail-m_7548809065351022967user-content-impact-on-existing-code" class="m_-4588606749269976813gmail-m_7548809065351022967anchor gmail_msg" href="https://gist.github.com/erica/db9ce92b3d23cb20799460f603c0ae7c#impact-on-existing-code" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none;float:left;padding-right:4px;line-height:1" target="_blank"><u class="gmail_msg"></u><u class="gmail_msg"></u><u class="gmail_msg"></u><u class="gmail_msg"></u></a>Impact on Existing Code</h2><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">This proposal is breaking and would require migration.</p><h2 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom:1px solid rgb(238,238,238);color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;background-color:rgb(255,255,255)" class="gmail_msg"><a id="m_-4588606749269976813gmail-m_7548809065351022967user-content-alternatives-considered" class="m_-4588606749269976813gmail-m_7548809065351022967anchor gmail_msg" href="https://gist.github.com/erica/db9ce92b3d23cb20799460f603c0ae7c#alternatives-considered" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none;float:left;padding-right:4px;line-height:1" target="_blank"><u class="gmail_msg"></u><u class="gmail_msg"></u><u class="gmail_msg"></u><u class="gmail_msg"></u></a>Alternatives Considered</h2><ul style="box-sizing:border-box;padding-left:2em;margin-top:0px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px;background-color:rgb(255,255,255);margin-bottom:0px" class="gmail_msg"><li style="box-sizing:border-box" class="gmail_msg">Leaving the grammar as-is, albeit confusing</li><li style="box-sizing:border-box;margin-top:0.25em" class="gmail_msg">Retaining <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">case</code> and replacing the equal sign with <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">~=</code> (pattern matching) or <code style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-radius:3px" class="gmail_msg">:</code> (to match the switch statement).</li></ul><div class="gmail_msg"><br class="gmail_msg"></div></div></div><br class="gmail_msg">_______________________________________________<br class="gmail_msg">
swift-evolution mailing list<br class="gmail_msg">
<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a><br class="gmail_msg">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="gmail_msg">
<br class="gmail_msg"></blockquote></div><br class="gmail_msg"></div></div>
_______________________________________________<br class="gmail_msg">
swift-evolution mailing list<br class="gmail_msg">
<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a><br class="gmail_msg">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="gmail_msg">
</blockquote></div></div>