<html><head><style>body{font-family:Helvetica,Arial;font-size:13px}</style></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">It doesn’t compile because you’re switching on the Optional and trying to pattern match it to Coin.</div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;"><br></div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">It compiles right when you pattern match it to Optional&lt;Coin&gt;:</div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;"><br></div><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; margin: 0px;"><p style="margin: 0px; font-size: 14px; line-height: normal; font-family: Monaco;"><span style="font-variant-ligatures: no-common-ligatures;">switch</span><span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="font-variant-ligatures: no-common-ligatures;">result</span><span style="font-variant-ligatures: no-common-ligatures;"> {</span></p>
<p style="margin: 0px; font-size: 14px; line-height: normal; font-family: Monaco;"><span style="font-variant-ligatures: no-common-ligatures;">case</span><span style="font-variant-ligatures: no-common-ligatures"> .</span><span style="font-variant-ligatures: no-common-ligatures;">heads</span><span style="font-variant-ligatures: no-common-ligatures">?: </span><span style="font-variant-ligatures: no-common-ligatures;">print</span><span style="font-variant-ligatures: no-common-ligatures">(</span><span style="font-variant-ligatures: no-common-ligatures;">"heads"</span><span style="font-variant-ligatures: no-common-ligatures">)</span></p>
<p style="margin: 0px; font-size: 14px; line-height: normal; font-family: Monaco;"><span style="font-variant-ligatures: no-common-ligatures;">case</span><span style="font-variant-ligatures: no-common-ligatures"> .</span><span style="font-variant-ligatures: no-common-ligatures;">tails</span><span style="font-variant-ligatures: no-common-ligatures">?: </span><span style="font-variant-ligatures: no-common-ligatures;">print</span><span style="font-variant-ligatures: no-common-ligatures">(</span><span style="font-variant-ligatures: no-common-ligatures;">"tails"</span><span style="font-variant-ligatures: no-common-ligatures">)</span></p>
<p style="margin: 0px; font-size: 14px; line-height: normal; font-family: Monaco;"><span style="font-variant-ligatures: no-common-ligatures;">case</span><span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="font-variant-ligatures: no-common-ligatures;">nil</span><span style="font-variant-ligatures: no-common-ligatures;">: </span><span style="font-variant-ligatures: no-common-ligatures;">print</span><span style="font-variant-ligatures: no-common-ligatures;">(</span><span style="font-variant-ligatures: no-common-ligatures">"not yet flipped"</span><span style="font-variant-ligatures: no-common-ligatures;">)</span></p>
<p style="margin: 0px; font-size: 14px; line-height: normal; font-family: Monaco;"><span style="font-variant-ligatures: no-common-ligatures;">}</span></p></div><div><br></div>Best,<div>Krzysztof<br> <div id="bloop_sign_1462463405386560000" class="bloop_sign"></div> <br><p class="airmail_on">On 5 May 2016 at 17:42:24, Eric Miller via swift-evolution (<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>) wrote:</p> <blockquote type="cite" class="clean_bq"><span><div><div></div><div>



<title></title>


<div dir="ltr">Wondering if you guys think this is a reasonable
idea.
<div><br></div>
<div>I was switching on an optional enum today, and naturally
gravitated towards including nil as a case:</div>
<div><br></div>
<div>enum Coin {</div>
<div>&nbsp; case heads</div>
<div>&nbsp; case tails</div>
<div>}</div>
<div>var result: Coin?</div>
<div><br></div>
<div>switch result {</div>
<div>case heads: print("heads")</div>
<div>case tails:&nbsp;print("tails")</div>
<div>case nil:&nbsp;print("not yet flipped") // exhaustive</div>
<div>}</div>
<div><br></div>
<div>Doesn't compile, and of course I can if-let or guard to unwrap
instead, but I like the compactness of this.</div>
</div>


_______________________________________________<br>swift-evolution mailing list<br>swift-evolution@swift.org<br>https://lists.swift.org/mailman/listinfo/swift-evolution<br></div></div></span></blockquote></div></body></html>