<div dir="ltr">Good grief. I think you&#39;re right. <div><br></div><div>Some how, a long time ago, I got it into my head that the order in which each part of the ternary got evaluated would cause problems for this kind of thing.</div><div><br></div><div>I&#39;ve had a huge blindspot and I&#39;ve been railing on the list for something I don&#39;t need for weeks. </div><div><br></div><div>Wow, I couldn&#39;t be more embarassed. </div><div><br></div><div>But I&#39;m happy too, because I can go ahead and just use a chained ternary.<br></div><div><br></div><div>Sorry all, and thanks.</div><div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, May 23, 2016 at 6:26 PM, Dany St-Amant <span dir="ltr">&lt;<a href="mailto:dsa.mls@icloud.com" target="_blank">dsa.mls@icloud.com</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>Le 20 mai 2016 à 07:14, Charles Constant via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; a écrit :</div><br><div><div dir="ltr">I wrote some code tonight to experiment with this kind of thing. I apologize if it&#39;s off-topic for the thread, but it might be useful to others who want to experiment. <div><br></div><div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(145,145,145);background-color:rgb(68,68,68);min-height:12px"><span></span><br></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(255,255,255);background-color:rgb(68,68,68);min-height:12px"><span></span><br></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(145,145,145);background-color:rgb(68,68,68)"><span>//: Playground - noun: a place where people can play</span></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(255,255,255);background-color:rgb(68,68,68);min-height:12px"><span></span><br></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(255,255,255);background-color:rgb(68,68,68)"><span style="color:rgb(194,52,155)">import</span><span> Cocoa</span></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(255,255,255);background-color:rgb(68,68,68);min-height:12px"><span></span><br></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(194,52,155);background-color:rgb(68,68,68)"><span>infix</span><span style="color:rgb(255,255,255)"> </span><span>operator</span><span style="color:rgb(255,255,255)"> • { </span><span>precedence</span><span style="color:rgb(255,255,255)"> </span><span style="color:rgb(139,132,207)">180</span><span style="color:rgb(255,255,255)"> }</span></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(194,52,155);background-color:rgb(68,68,68)"><span>infix</span><span style="color:rgb(255,255,255)"> </span><span>operator</span><span style="color:rgb(255,255,255)"> → { </span><span>associativity</span><span style="color:rgb(255,255,255)"> left </span><span>precedence</span><span style="color:rgb(255,255,255)"> </span><span style="color:rgb(139,132,207)">70</span><span style="color:rgb(255,255,255)"> }</span></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(194,52,155);background-color:rgb(68,68,68)"><span>infix</span><span style="color:rgb(255,255,255)"> </span><span>operator</span><span style="color:rgb(255,255,255)"> … { </span><span>associativity</span><span style="color:rgb(255,255,255)"> right </span><span>precedence</span><span style="color:rgb(255,255,255)"> </span><span style="color:rgb(139,132,207)">60</span><span style="color:rgb(255,255,255)"> }</span></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(255,255,255);background-color:rgb(68,68,68);min-height:12px"><span></span><br></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(255,255,255);background-color:rgb(68,68,68)"><span style="color:rgb(194,52,155)">func</span><span> → &lt;T&gt;( lhs: </span><span style="color:rgb(0,175,202)">Bool</span><span>, rhs: </span><span style="color:rgb(0,175,202)">T</span><span> ) -&gt; </span><span style="color:rgb(0,175,202)">T</span><span>? {</span></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(255,255,255);background-color:rgb(68,68,68)"><span><span style="white-space:pre-wrap">        </span></span><span style="color:rgb(194,52,155)">return</span><span> lhs ? rhs : </span><span style="color:rgb(194,52,155)">nil</span></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(255,255,255);background-color:rgb(68,68,68)"><span>}</span></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(255,255,255);background-color:rgb(68,68,68);min-height:12px"><span></span><br></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(255,255,255);background-color:rgb(68,68,68)"><span style="color:rgb(194,52,155)">func</span><span> … &lt;T&gt;( lhs:</span><span style="color:rgb(0,175,202)">T</span><span>?, rhs:</span><span style="color:rgb(0,175,202)">T</span><span> ) -&gt; </span><span style="color:rgb(0,175,202)">T</span><span> {</span></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(255,255,255);background-color:rgb(68,68,68)"><span><span style="white-space:pre-wrap">        </span></span><span style="color:rgb(194,52,155)">return</span><span> lhs != </span><span style="color:rgb(194,52,155)">nil</span><span> ? lhs! : rhs</span></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(255,255,255);background-color:rgb(68,68,68)"><span>}</span></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(255,255,255);background-color:rgb(68,68,68);min-height:12px"><span></span><br></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(255,255,255);background-color:rgb(68,68,68)"><span style="color:rgb(194,52,155)">func</span><span> depends&lt;I,O&gt;( dep:</span><span style="color:rgb(0,175,202)">I</span><span>, </span><span style="color:rgb(194,52,155)">_</span><span> closure: (</span><span style="color:rgb(0,175,202)">I</span><span>)-&gt;(</span><span style="color:rgb(0,175,202)">O</span><span>) ) -&gt; </span><span style="color:rgb(0,175,202)">O</span><span> {</span></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(255,255,255);background-color:rgb(68,68,68)"><span><span style="white-space:pre-wrap">        </span></span><span style="color:rgb(194,52,155)">return</span><span> closure( dep )</span></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(255,255,255);background-color:rgb(68,68,68)"><span>}</span></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(255,255,255);background-color:rgb(68,68,68);min-height:12px"><span></span><br></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(255,255,255);background-color:rgb(68,68,68)"><span style="color:rgb(194,52,155)">func</span><span> • &lt;I,O&gt;( lhs: </span><span style="color:rgb(0,175,202)">I</span><span>, rhs: (</span><span style="color:rgb(0,175,202)">I</span><span>)-&gt;(</span><span style="color:rgb(0,175,202)">O</span><span>) ) -&gt; </span><span style="color:rgb(0,175,202)">O</span><span> {</span></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(255,255,255);background-color:rgb(68,68,68)"><span><span style="white-space:pre-wrap">        </span></span><span style="color:rgb(194,52,155)">return</span><span> </span><span style="color:rgb(147,200,106)">depends</span><span>( lhs, rhs )</span></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(255,255,255);background-color:rgb(68,68,68)"><span>}</span></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(255,255,255);background-color:rgb(68,68,68);min-height:12px"><span></span><br></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(145,145,145);background-color:rgb(68,68,68)"><span>/* Example using &quot;depends&quot; */</span></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(255,255,255);background-color:rgb(68,68,68);min-height:12px"><span></span><br></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(194,52,155);background-color:rgb(68,68,68)"><span>let</span></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(255,255,255);background-color:rgb(68,68,68)"><span><span style="white-space:pre-wrap">        </span>str:</span><span style="color:rgb(0,175,202)">String</span><span>,</span></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(255,255,255);background-color:rgb(68,68,68)"><span><span style="white-space:pre-wrap">        </span>i = </span><span style="color:rgb(139,132,207)">7</span></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(255,255,255);background-color:rgb(68,68,68);min-height:12px"><span></span><br></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(147,200,106);background-color:rgb(68,68,68)"><span>str</span><span style="color:rgb(255,255,255)"> = </span><span>depends</span><span style="color:rgb(255,255,255)">( </span><span>i</span><span style="color:rgb(255,255,255)"> ){</span></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(255,255,255);background-color:rgb(68,68,68)"><span><span style="white-space:pre-wrap">        </span>$0==</span><span style="color:rgb(139,132,207)">2</span><span> </span><span style="color:rgb(147,200,106)">→</span><span> </span><span style="color:rgb(228,68,72)">&quot;two&quot;</span><span> </span><span style="color:rgb(147,200,106)">…</span></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(255,255,255);background-color:rgb(68,68,68)"><span><span style="white-space:pre-wrap">        </span>$0==</span><span style="color:rgb(139,132,207)">3</span><span> </span><span style="color:rgb(147,200,106)">→</span><span> </span><span style="color:rgb(228,68,72)">&quot;three&quot;</span><span> </span><span style="color:rgb(147,200,106)">…</span></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(255,255,255);background-color:rgb(68,68,68)"><span><span style="white-space:pre-wrap">        </span>$0==</span><span style="color:rgb(139,132,207)">4</span><span> </span><span style="color:rgb(147,200,106)">→</span><span> </span><span style="color:rgb(228,68,72)">&quot;four&quot;</span><span> </span><span style="color:rgb(147,200,106)">…</span></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(228,68,72);background-color:rgb(68,68,68)"><span style="color:rgb(255,255,255)"><span style="white-space:pre-wrap">        </span></span><span>&quot;other&quot;</span></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(255,255,255);background-color:rgb(68,68,68)"><span>}</span></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(255,255,255);background-color:rgb(68,68,68);min-height:12px"><span></span><br></div></div></div></div></blockquote><div><br></div></span><div>Hmm… replacing -&gt; by ?, and … by : you get:</div><div><br></div><div><span class=""><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:#4f8187">str</span> = <span style="color:#31595d">depends</span>( <span style="color:#4f8187">i</span> ){</div></span><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">    $0==<span style="color:#272ad8">2</span> ? <span style="color:#d12f1b">&quot;two&quot;</span> :</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">    $0==<span style="color:#272ad8">3</span> ? <span style="color:#d12f1b">&quot;three&quot;</span> :</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">    $0==<span style="color:#272ad8">4</span> ? <span style="color:#d12f1b">&quot;four&quot;</span> :</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(209,47,27)"><span style="color:#000000">    </span>&quot;other&quot;</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">}</div><div><br></div><div>which work as is without a need to define new operators.</div><span class="HOEnZb"><font color="#888888"><div><br></div><div>Dany</div><div><br></div></font></span></div><div><div class="h5"><blockquote type="cite"><div><div dir="ltr"><div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(145,145,145);background-color:rgb(68,68,68)"><span>/* Example using &quot;•&quot; operator as &quot;depends&quot; */</span></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(255,255,255);background-color:rgb(68,68,68);min-height:12px"><span></span><br></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(255,255,255);background-color:rgb(68,68,68)"><span style="color:rgb(194,52,155)">enum</span><span> People { </span><span style="color:rgb(194,52,155)">case</span><span> Kurtz, Popescu, Lime, Martins }</span></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(255,255,255);background-color:rgb(68,68,68)"><span style="color:rgb(194,52,155)">enum</span><span> Order { </span><span style="color:rgb(194,52,155)">case</span><span> First, Second, Third, Unknown }</span></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(255,255,255);background-color:rgb(68,68,68);min-height:12px"><span></span><br></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(194,52,155);background-color:rgb(68,68,68)"><span>let</span></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(255,255,255);background-color:rgb(68,68,68)"><span><span style="white-space:pre-wrap">        </span>order:</span><span style="color:rgb(147,200,106)">Order</span><span>,</span></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(255,255,255);background-color:rgb(68,68,68)"><span><span style="white-space:pre-wrap">        </span>person:</span><span style="color:rgb(147,200,106)">People</span><span> = .</span><span style="color:rgb(147,200,106)">Lime</span></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(255,255,255);background-color:rgb(68,68,68);min-height:12px"><span></span><br></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(147,200,106);background-color:rgb(68,68,68)"><span>order</span><span style="color:rgb(255,255,255)"> = </span><span>person</span><span style="color:rgb(255,255,255)"> </span><span>•</span><span style="color:rgb(255,255,255)"> {</span></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(147,200,106);background-color:rgb(68,68,68)"><span style="color:rgb(255,255,255)"><span style="white-space:pre-wrap">        </span>$0 </span><span>==</span><span style="color:rgb(255,255,255)"> .</span><span>Kurtz</span><span style="color:rgb(255,255,255)"> </span><span>→</span><span style="color:rgb(255,255,255)"> .</span><span>First</span><span style="color:rgb(255,255,255)"> </span><span>…</span></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(147,200,106);background-color:rgb(68,68,68)"><span style="color:rgb(255,255,255)"><span style="white-space:pre-wrap">        </span>$0 </span><span>==</span><span style="color:rgb(255,255,255)"> .</span><span>Popescu</span><span style="color:rgb(255,255,255)"> </span><span>→</span><span style="color:rgb(255,255,255)"> .</span><span>Second</span><span style="color:rgb(255,255,255)"> </span><span>…</span></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(147,200,106);background-color:rgb(68,68,68)"><span style="color:rgb(255,255,255)"><span style="white-space:pre-wrap">        </span>$0 </span><span>==</span><span style="color:rgb(255,255,255)"> .</span><span>Lime</span><span style="color:rgb(255,255,255)"> </span><span>→</span><span style="color:rgb(255,255,255)"> .</span><span>Third</span><span style="color:rgb(255,255,255)"> </span><span>…</span></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(147,200,106);background-color:rgb(68,68,68)"><span style="color:rgb(255,255,255)"><span style="white-space:pre-wrap">        </span>.</span><span>Unknown</span></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(255,255,255);background-color:rgb(68,68,68)"><span>}</span></div><div style="margin:0px;font-size:10px;line-height:normal;font-family:&#39;Fantasque Sans Mono&#39;;color:rgb(255,255,255);background-color:rgb(68,68,68);min-height:12px"><span></span><br></div><div><div><div><br></div><div><div>I also have some trepidation about posting it here, because it might have bugs. I wans&#39;t sure what &quot;precedence&quot; and &quot;associativity&quot; should be, for example. But it does make it more convenient to test alternative characters for operators, etc.</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Apr 9, 2016 at 12:05 AM, Vladimir.S 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:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span><br>
On 09.04.2016 9:31, Brent Royal-Gordon wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
This design is still very much under development—it hasn&#39;t even been reviewed, let alone added to the language. Here&#39;s the draft proposal:&lt;<a href="https://github.com/jtbandes/swift-evolution/blob/case-enumerable/proposals/0000-derived-collection-of-enum-cases.md" rel="noreferrer" target="_blank">https://github.com/jtbandes/swift-evolution/blob/case-enumerable/proposals/0000-derived-collection-of-enum-cases.md</a>&gt;<br>
<br>
I&#39;m not saying that this will necessarily be a solution that ends up being accepted—I&#39;m merely saying that yes, it&#39;s something people are thinking about and designing; it&#39;s just been inactive for a few weeks.<br>
</blockquote>
<br></span>
Oh, I see. Thank you for letting know. Just missed &quot;you would be able&quot; in your previous message, did read it as &quot;you are able&quot;, so was trying to find this in current Swift version. OK, glad to know that most likely we&#39;ll have improvements in enums eterations for Swift 3.0.<div><div><br>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">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>
</div></div></blockquote></div><br></div></div>
_______________________________________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div></blockquote></div></div></div><br></div></blockquote></div><br></div></div>