<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="">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="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> i = [.</span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">Red</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">:</span>0xff0000<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">, .</span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">Green</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">:</span>0x00ff00<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">, .</span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">Blue</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">:</span>0x0000ff<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">][</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">color</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">]</span></div><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: #000000" 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<Color> (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="font-variant-ligatures: no-common-ligatures; color: #000000" 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="font-variant-ligatures: no-common-ligatures; color: #000000" 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="font-variant-ligatures: no-common-ligatures; color: #000000" class=""><br class=""></span></div><div><blockquote type="cite" class=""><div class="">On Dec 22, 2015, at 8:04 AM, Félix Cloutier 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 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 <<a href="mailto:charles@charlesism.com" class="">charles@charlesism.com</a>> 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="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></div></blockquote></div><br class=""></div></body></html>