<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="">I know, but that won't support pattern matching.<div class=""><br class=""><div class="">
<span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Lucida Grande';  font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; ">Félix</span>
</div>
<br class=""><div><blockquote type="cite" class=""><div class="">Le 23 déc. 2015 à 02:22:07, David Waite &lt;<a href="mailto:david@alkaline-solutions.com" class="">david@alkaline-solutions.com</a>&gt; a écrit :</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">In the case where your input is hashable, you could just do:<div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(39, 42, 216);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span><span style="" class="">&nbsp;i = [.</span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">Red</span><span style="" class="">:</span>0xff0000<span style="" class="">, .</span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">Green</span><span style="" class="">:</span>0x00ff00<span style="" class="">, .</span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">Blue</span><span style="" class="">:</span>0x0000ff<span style="" class="">][</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">color</span><span style="" class="">]</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(39, 42, 216);" class=""><span style="" class=""><br class=""></span></div><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" class=""><span style="font-size: 11px;" class="">this would mean that color must be a Color and not an Optional&lt;Color&gt; (because of swift 2.x limitations)</span></font></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(39, 42, 216);" class=""><span style="" class=""><br class=""></span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(39, 42, 216);" class=""><span style="" class="">-DW</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(39, 42, 216);" class=""><span style="" class=""><br class=""></span></div><div class=""><blockquote type="cite" class=""><div class="">On Dec 22, 2015, at 8:04 AM, Félix Cloutier via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">I like the gist of it too, though you seem to introduce both a new keyword and a new syntax. (To be clear, I like the syntax but I'm ambivalent towards reusing switch instead of which.)<br class=""><br class="">My minor suggestions would to avoid braces for things that aren't scopes; that either the comma or the the question mark is redundant in their current position (you need a start delimiter or an end delimiter but you don't need both); and that it needs a way to handle a default case if enumeration isn't exhaustive (I'd do that by returning an optional).<br class=""><br class=""><blockquote type="cite" class="">let i = which color (.Red: 0xff0000, .Green: 0x00ff00, .Blue: 0x0000ff) ?? 0x000000<br class=""></blockquote><br class=""><br class="">Thinking out loud, once you remove the question marks it really looks like a dictionary literal, so maybe it could even use square brackets to close the gap.<br class=""><br class=""><blockquote type="cite" class="">let i = which color [.Red: 0xff0000, .Green: 0x00ff00, .Blue: 0x0000ff] ?? 0x000000<br class=""></blockquote><br class=""><br class="">I thought about subscripting a dictionary literal in place:<br class=""><br class=""><blockquote type="cite" class="">[Color.Red: 0xff0000, ...][color] ?? 0x000000<br class=""></blockquote><br class=""><br class="">but that won't support elaborate pattern matching, and I think that this is a deal breaker for the functional folks.<br class=""><br class="">Félix<br class=""><br class=""><blockquote type="cite" class="">Le 22 déc. 2015 à 09:31:32, Charles Constant &lt;<a href="mailto:charles@charlesism.com" class="">charles@charlesism.com</a>&gt; a écrit :<br class=""><br class="">Just goofing on this a little. What if we called it a "which" statement, instead of a "switch" statement? It's a bit cutesy, but not too verbose, and it makes sense if you read it aloud.<br class=""><br class="">let i = which color {<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>? .Red: 0xFF0000, <br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>? .Green: 0x00FF00, <br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>? .Blue: 0x00000FF<br class="">}<br class=""><br class="">let i = which boo {<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>? true: 1, <br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>? false: 0, <br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>? nil: -1<br class="">}<br class=""><br class=""></blockquote><br class="">_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></div></blockquote></div><br class=""></div></div></div></blockquote></div><br class=""></div></body></html>