<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">So… Is your idea that wrapping a SomeEnum in an Optional would add some “invalid” case to SomeEnum, or that switching on a SomeEnum? would be implicitly rewrite:<blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(187, 44, 162);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">switch</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">result</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> {</span></div></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> .heads: </span><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">print</span><span style="font-variant-ligatures: no-common-ligatures" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"heads"</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> .tails: </span><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">print</span><span style="font-variant-ligatures: no-common-ligatures" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"tails"</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(209, 47, 27);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">case</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> .</span><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">none</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">: </span><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">print</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(</span><span style="font-variant-ligatures: no-common-ligatures" class="">"not yet flipped"</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">) </span><span style="font-variant-ligatures: no-common-ligatures; color: #008400" class="">// exhaustive</span></div></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div></div></blockquote><div class=""><div class=""><span style="font-variant-ligatures: no-common-ligatures" class="">to:</span></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(187, 44, 162);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">switch</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">result</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> {</span></div></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(187, 44, 162);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">case</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> .</span><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">none</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">: </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(61, 29, 129);" class="">print</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(</span><span style="color: rgb(209, 47, 27); font-variant-ligatures: no-common-ligatures;" class="">"not yet flipped"</span><span style="font-variant-ligatures: no-common-ligatures;" class="">)</span></div></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> .</span><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">some</span><span style="font-variant-ligatures: no-common-ligatures" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> _result):</span></div></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">switch</span><span style="font-variant-ligatures: no-common-ligatures" class=""> _result {</span></div></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> .</span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">heads</span><span style="font-variant-ligatures: no-common-ligatures" class="">: </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(61, 29, 129);" class="">print</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(209, 47, 27);" class="">"heads"</span><span style="font-variant-ligatures: no-common-ligatures;" class="">)</span></div></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> .</span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">tails</span><span style="font-variant-ligatures: no-common-ligatures" class="">: </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(61, 29, 129);" class="">print</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(209, 47, 27);" class="">"tails"</span><span style="font-variant-ligatures: no-common-ligatures;" class="">)</span></div></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> }</span></div></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div></div></blockquote><div class=""><div class=""><br class=""></div><div><blockquote type="cite" class=""><div class="">On May 5, 2016, at 10:40 AM, Eric Miller via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Wondering if you guys think this is a reasonable idea.<div class=""><br class=""></div><div class="">I was switching on an optional enum today, and naturally gravitated towards including nil as a case:</div><div class=""><br class=""></div><div class="">enum Coin {</div><div class=""> case heads</div><div class=""> case tails</div><div class="">}</div><div class="">var result: Coin?</div><div class=""><br class=""></div><div class="">switch result {</div><div class="">case heads: print("heads")</div><div class="">case tails: print("tails")</div><div class="">case nil: print("not yet flipped") // exhaustive</div><div class="">}</div><div class=""><br class=""></div><div class="">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 class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></div></div></body></html>