<div dir="ltr">Hi Amir,<div><br></div><div>I put forward a proposal a short while ago that may allow you to achieve similar to what you want, it is here:</div><div><br></div><b>Declare variables in &#39;case&#39; labels with multiple patterns</b><div><a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160118/007431.html" target="_blank">https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160118/007431.html</a><br></div><div><br></div><div><a href="https://github.com/apple/swift-evolution/pull/119">https://github.com/apple/swift-evolution/pull/119</a><br></div><div><br></div><div><div>It would allow you to express your logic like this:</div><div><br></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)">  switch</span> vehicle {</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)">  case</span> .Car(<span style="color:rgb(187,44,162)">let</span> color), .Motorcycle(<span style="color:rgb(187,44,162)">let</span> color), .Helicopter(<span style="color:rgb(187,44,162)">let</span> color):</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">      <span style="color:rgb(187,44,162)">switch</span> color {</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">      <span style="color:rgb(187,44,162)">case</span> .Red:   ...</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">      <span style="color:rgb(187,44,162)">case</span> .Green: ...</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">      <span style="color:rgb(187,44,162)">case</span> .Blue:  ...</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">      }</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">






</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">  }</p></div></div><div><br></div><div>That proposal seemed to be well received with no votes against, and after a few tweaks seemed to have support from the Swift team.</div><div><br></div><div>What do you think about that approach? It&#39;s not quite as concise as what you proposed but it can be generalised more easily, and handles pattern matching of cases where `color` may not be the only associated value.</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Feb 24, 2016 at 1:13 AM, Amir Michail via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><br><div><span class=""><blockquote type="cite"><div>On Feb 23, 2016, at 7:27 AM, Taras Zakharko &lt;<a href="mailto:taras.zakharko@uzh.ch" target="_blank">taras.zakharko@uzh.ch</a>&gt; wrote:</div><br><div><div style="word-wrap:break-word">I think that other designs (e.g. using classes/structs/protocols) offer a much better solution for this particular problem<div><br></div></div></div></blockquote><div><br></div></span><div>That might be more work than just listing all the cases...</div><div><div class="h5"><div><br></div><blockquote type="cite"><div><div style="word-wrap:break-word"><div><div><blockquote type="cite"><div>On 23 Feb 2016, at 13:17, Amir Michail via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br><div><blockquote type="cite" style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br>On Feb 22, 2016, at 10:11 PM, Brent Royal-Gordon &lt;<a href="mailto:brent@architechies.com" target="_blank">brent@architechies.com</a>&gt; wrote:<br><br><blockquote type="cite">For example:<br><br>enum Color {<br><span style="white-space:pre-wrap">        </span>...<br>}<br><br>enum Vehicle {<br><span style="white-space:pre-wrap">        </span>case Car(Color)<br><span style="white-space:pre-wrap">        </span>case Motorcycle(Color)<br><span style="white-space:pre-wrap">        </span>...<br>}<br><br>switch vehicle {<br><span style="white-space:pre-wrap">        </span>case _(.Red): … // pattern match based on associated value only<br>}<br></blockquote><br>As usual, Amir:<span> </span><br><br>1. Why do you want this feature?<br></blockquote><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">In this example, if there are many kinds of vehicles, it would be annoying to have to write a case for each one to match associated value .Red.</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><blockquote type="cite" style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br>2. What&#39;s actually wrong with the status quo?<br><br></blockquote><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">What would that be for this example? Many cases?</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><blockquote type="cite" style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">3. Can you talk about a non-toy example you&#39;ve encountered where it would have made your code better?<br><br>4. Can you talk about the proposed design in a little more detail? Are there weird edge cases, and how would you handle them? (In the case of this feature, here&#39;s one I see: Suppose you have two different associated value types but they both have a .Red case. What happens then?)<br><br>A half-dozen-word subject line and a code example simply aren&#39;t enough to evaluate a proposal. Without knowing exactly what you&#39;re proposing and why you think it&#39;s a good idea, we can&#39;t really evaluate it properly.<br><br>--<span> </span><br>Brent Royal-Gordon<br>Architechies<br><br></blockquote><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">_______________________________________________</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">swift-evolution mailing list</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important"><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a></span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important"><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span></div></blockquote></div><br></div></div></div></blockquote></div></div></div><br></div><br>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br></blockquote></div><br></div>