<div dir="ltr">I like the simplicity of &#39;unwrap&#39; solving the issue of repetition, but it assumes &#39;let&#39; in each example I&#39;ve seen. &#39;guard var x = x&#39; may not be written as frequently, but it is still valid. I can&#39;t imagine the intention would be that &#39;unwrap&#39; is only for &#39;let&#39;<div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Sun, Oct 30, 2016 at 5:18 AM Jay Abbott 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"><div class="m_1606005923312976759markdown-here-wrapper gmail_msg"><p style="margin:0px 0px 1.2em!important" class="gmail_msg"></p><div class="m_1606005923312976759markdown-here-exclude gmail_msg"><p class="gmail_msg"></p><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg"><pre style="box-sizing:border-box;font-family:Consolas,&#39;Liberation Mono&#39;,Menlo,Courier,monospace;font-size:13.600000381469727px;margin-top:0px;margin-bottom:16px;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;color:rgb(51,51,51)" class="gmail_msg"><code style="box-sizing:border-box;font-family:Consolas,&#39;Liberation Mono&#39;,Menlo,Courier,monospace;padding:0px;margin:0px;background-color:transparent;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-break:normal;border:0px;display:inline;overflow:visible;line-height:inherit;word-wrap:normal" class="gmail_msg">@unwrappable(type: Int)
public enum Count {
    case none // not unwrappable
    case many // not unwrappable
    case some(Int)
    case owed(Int)
    case something(String) // not unwrappable
    case multiple(Int, Int) // not unwrappable
}
</code></pre></div>
</div></blockquote><p class="gmail_msg"></p></div><p style="margin:0px 0px 1.2em!important" class="gmail_msg"></p>
</div></div><div dir="ltr" class="gmail_msg"><div class="m_1606005923312976759markdown-here-wrapper gmail_msg"><p style="margin:0px 0px 1.2em!important" class="gmail_msg">Instead of requiring the <code style="font-size:1em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="gmail_msg">@unwrappable</code> attribute, why not have <code style="font-size:1em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="gmail_msg">unwrap</code> work normally when the type can be inferred, or require hints when it can’t:</p>
<pre style="font-size:1em;font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px" class="gmail_msg"><code class="m_1606005923312976759hljs m_1606005923312976759language-swift gmail_msg" style="font-size:1em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline;white-space:pre-wrap;overflow:auto;border-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;display:block!important;display:block;overflow-x:auto;padding:0.5em;color:rgb(51,51,51);background:rgb(248,248,248) none repeat scroll 0% 0%"><span class="m_1606005923312976759hljs-comment gmail_msg" style="color:rgb(153,153,136);font-style:italic">// For an optional (or any other enum with only one wrapped type)</span>
guard unwrap x <span class="m_1606005923312976759hljs-keyword gmail_msg" style="color:rgb(51,51,51);font-weight:bold">else</span> { <span class="m_1606005923312976759hljs-keyword gmail_msg" style="color:rgb(51,51,51);font-weight:bold">return</span> }
<span class="m_1606005923312976759hljs-comment gmail_msg" style="color:rgb(153,153,136);font-style:italic">// For an enum of type Count as defined above</span>
guard unwrap myCount <span class="m_1606005923312976759hljs-keyword gmail_msg" style="color:rgb(51,51,51);font-weight:bold">else</span> { <span class="m_1606005923312976759hljs-keyword gmail_msg" style="color:rgb(51,51,51);font-weight:bold">return</span> } <span class="m_1606005923312976759hljs-comment gmail_msg" style="color:rgb(153,153,136);font-style:italic">// compiler error - type can&#39;t be determined</span>
guard unwrap(myCount: <span class="m_1606005923312976759hljs-type gmail_msg" style="color:rgb(68,85,136);font-weight:bold">Int</span>) <span class="m_1606005923312976759hljs-keyword gmail_msg" style="color:rgb(51,51,51);font-weight:bold">else</span> { <span class="m_1606005923312976759hljs-keyword gmail_msg" style="color:rgb(51,51,51);font-weight:bold">return</span> } <span class="m_1606005923312976759hljs-comment gmail_msg" style="color:rgb(153,153,136);font-style:italic">// Success for &#39;some&#39; or &#39;owed&#39; (implicit shadowing)</span>
guard unwrap(<span class="m_1606005923312976759hljs-keyword gmail_msg" style="color:rgb(51,51,51);font-weight:bold">let</span> someOrOwed: <span class="m_1606005923312976759hljs-type gmail_msg" style="color:rgb(68,85,136);font-weight:bold">Int</span>) myCount <span class="m_1606005923312976759hljs-keyword gmail_msg" style="color:rgb(51,51,51);font-weight:bold">else</span> { <span class="m_1606005923312976759hljs-keyword gmail_msg" style="color:rgb(51,51,51);font-weight:bold">return</span> } <span class="m_1606005923312976759hljs-comment gmail_msg" style="color:rgb(153,153,136);font-style:italic">// Success for &#39;some&#39; or &#39;owed&#39; (no shadowing)</span>
guard unwrap(<span class="m_1606005923312976759hljs-keyword gmail_msg" style="color:rgb(51,51,51);font-weight:bold">let</span> x: <span class="m_1606005923312976759hljs-type gmail_msg" style="color:rgb(68,85,136);font-weight:bold">Int</span>, <span class="m_1606005923312976759hljs-keyword gmail_msg" style="color:rgb(51,51,51);font-weight:bold">let</span> y: <span class="m_1606005923312976759hljs-type gmail_msg" style="color:rgb(68,85,136);font-weight:bold">Int</span>) myCount <span class="m_1606005923312976759hljs-keyword gmail_msg" style="color:rgb(51,51,51);font-weight:bold">else</span> { <span class="m_1606005923312976759hljs-keyword gmail_msg" style="color:rgb(51,51,51);font-weight:bold">return</span> } <span class="m_1606005923312976759hljs-comment gmail_msg" style="color:rgb(153,153,136);font-style:italic">// Success for &#39;multiple&#39; (no shadowing)</span>
</code></pre>
<p style="margin:0px 0px 1.2em!important" class="gmail_msg">Notes:</p>
<ul style="margin:1.2em 0px;padding-left:2em" class="gmail_msg">
<li style="margin:0.5em 0px" class="gmail_msg"><code style="font-size:1em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="gmail_msg">unwrap x</code> is equivalent to <code style="font-size:1em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="gmail_msg">unwrap(x: T)</code> where there is a single unambiguous type.</li>
<li style="margin:0.5em 0px" class="gmail_msg">The <code style="font-size:1em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="gmail_msg">let</code> keyword probably could be implicit for the non-shadowing forms, like it is for the shadowing form, but makes it clear what’s going on.</li>
<li style="margin:0.5em 0px" class="gmail_msg">unwrap fails for <code style="font-size:1em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="gmail_msg">none</code> or <code style="font-size:1em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="gmail_msg">many</code> from the <code style="font-size:1em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="gmail_msg">Count</code> type, just as it does for <code style="font-size:1em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="gmail_msg">none</code> from Optional</li>
<li style="margin:0.5em 0px" class="gmail_msg">I <em class="gmail_msg">think</em> that this assumes Swift is not allowed to try to infer the most restrictive type for reference types. Haven’t really thought about this much.</li>
</ul>
<div title="MDH:PGNvZGUgc3R5bGU9ImJveC1zaXppbmc6Ym9yZGVyLWJveDtmb250LWZhbWlseTpDb25zb2xhcywn
TGliZXJhdGlvbiBNb25vJyxNZW5sbyxDb3VyaWVyLG1vbm9zcGFjZTtwYWRkaW5nOjBweDttYXJn
aW46MHB4O2JhY2tncm91bmQtY29sb3I6dHJhbnNwYXJlbnQ7Ym9yZGVyLXRvcC1sZWZ0LXJhZGl1
czozcHg7Ym9yZGVyLXRvcC1yaWdodC1yYWRpdXM6M3B4O2JvcmRlci1ib3R0b20tcmlnaHQtcmFk
aXVzOjNweDtib3JkZXItYm90dG9tLWxlZnQtcmFkaXVzOjNweDt3b3JkLWJyZWFrOm5vcm1hbDti
b3JkZXI6MHB4O2Rpc3BsYXk6aW5saW5lO292ZXJmbG93OnZpc2libGU7bGluZS1oZWlnaHQ6aW5o
ZXJpdDt3b3JkLXdyYXA6bm9ybWFsIiBjbGFzcz0iZ21haWxfbXNnIj48L2NvZGU+PGRpdiBjbGFz
cz0iZ21haWxfcXVvdGUiPjxibG9ja3F1b3RlIGNsYXNzPSJnbWFpbF9xdW90ZSIgc3R5bGU9Im1h
cmdpbjowIDAgMCAuOGV4O2JvcmRlci1sZWZ0OjFweCAjY2NjIHNvbGlkO3BhZGRpbmctbGVmdDox
ZXg7Ij48ZGl2IHN0eWxlPSJ3b3JkLXdyYXA6YnJlYWstd29y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yBhc3N1bWVzIFN3aWZ0IGlzIG5vdCBhbGxvd2VkIHRv
IHRyeSB0byBpbmZlciB0aGUgbW9zdCByZXN0cmljdGl2ZSB0eXBlIGZvciByZWZlcmVuY2UgdHlw
ZXMuIEhhdmVuJ3QgcmVhbGx5IHRob3VnaHQgYWJvdXQgdGhpcyBtdWNoLjxicj48YnI+PC9kaXY+
PC9kaXY+" style="height:0;width:0;max-height:0;max-width:0;overflow:hidden;font-size:0em;padding:0;margin:0" class="gmail_msg">​</div></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>