<div dir="ltr">Can&#39;t you define this yourself?  This worked in a Playground using Swift 2.1:<div><br></div>enum Ordering {<br>    case OrderedSame, OrderedAscending, OrderedDescending<br>}<br><br>infix operator &lt;=&gt; {}<br>func &lt;=&gt; &lt;T: Comparable&gt;(x: T, y: T) -&gt; Ordering {<br>    if x &lt; y {<br>        return .OrderedAscending<br>    } else if x &gt; y {<br>        return .OrderedDescending<br>    } else {<br>        return .OrderedSame<br>    }<br>}<br><br><br>let x = 3<br>let y = 4<br>switch x &lt;=&gt; y {<br>case .OrderedSame:<br>    print(3)<br>case .OrderedAscending:<br>    print(4)  // Executed<br>case .OrderedDescending:<br>    print(5)<br>}</div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Feb 4, 2016 at 12:52 PM, Ross O&#39;Brien 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 dir="ltr"><div>Compare two values, and react differently if the first is larger, the second is larger, or they are equal.</div><div><br></div><div>An if statement will result in an &#39;if { } else if { } else { }&#39; structure. A switch can be used (case _ where x &lt; y) but the compiler will complain that the switch is not exhaustive, resulting in a redundant &#39;default&#39; case.</div><div><br></div>I&#39;d like to propose this addition to the Comparable type:<div><br></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(187,44,162)">infix<span style="color:rgb(0,0,0)"> </span>operator<span style="color:rgb(0,0,0)"> &lt;=&gt; {}</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(112,61,170)"><span style="color:rgb(187,44,162)">func</span><span style="color:rgb(0,0,0)"> &lt;=&gt; &lt;C : </span>Comparable<span style="color:rgb(0,0,0)">&gt; (lhs: </span>C<span style="color:rgb(0,0,0)">, rhs:</span>C<span style="color:rgb(0,0,0)">) -&gt; </span>NSComparisonResult</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"><span style="white-space:pre-wrap">        </span><span style="color:rgb(187,44,162)">if</span> lhs <span style="color:rgb(61,29,129)">==</span> rhs</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="white-space:pre-wrap">        </span>{</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(61,29,129)"><span style="color:rgb(0,0,0)"><span style="white-space:pre-wrap">                </span></span><span style="color:rgb(187,44,162)">return</span><span style="color:rgb(0,0,0)"> .</span>OrderedSame</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="white-space:pre-wrap">        </span>}</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="white-space:pre-wrap">        </span><span style="color:rgb(187,44,162)">if</span> lhs <span style="color:rgb(61,29,129)">&lt;</span> rhs</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="white-space:pre-wrap">        </span>{</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(61,29,129)"><span style="color:rgb(0,0,0)"><span style="white-space:pre-wrap">                </span></span><span style="color:rgb(187,44,162)">return</span><span style="color:rgb(0,0,0)"> .</span>OrderedAscending</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="white-space:pre-wrap">        </span>}</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(61,29,129)"><span style="color:rgb(0,0,0)"><span style="white-space:pre-wrap">        </span></span><span style="color:rgb(187,44,162)">return</span><span style="color:rgb(0,0,0)"> .</span>OrderedDescending</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"><br></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-family:arial,sans-serif;font-size:small">This now allows code like this:</span><br></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-family:arial,sans-serif;font-size:small"><br></span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)">let</span> x = <span style="color:rgb(39,42,216)">3</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)">let</span> y = <span style="color:rgb(39,42,216)">4</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(187,44,162)">switch<span style="color:rgb(0,0,0)"> x </span><span style="color:rgb(49,89,93)">&lt;=&gt;</span><span style="color:rgb(0,0,0)"> y</span></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"><span style="color:rgb(187,44,162)">case</span> .OrderedSame:</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(61,29,129)"><span style="color:rgb(0,0,0)"><span style="white-space:pre-wrap">        </span></span>print<span style="color:rgb(0,0,0)">(</span><span style="color:rgb(39,42,216)">3</span><span style="color:rgb(0,0,0)">)</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)">case</span> .OrderedAscending:</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(61,29,129)"><span style="color:rgb(0,0,0)"><span style="white-space:pre-wrap">        </span></span>print<span style="color:rgb(0,0,0)">(</span><span style="color:rgb(39,42,216)">4</span><span style="color:rgb(0,0,0)">)</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)">case</span> .OrderedDescending:</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(61,29,129)"><span style="color:rgb(0,0,0)"><span style="white-space:pre-wrap">        </span></span>print<span style="color:rgb(0,0,0)">(</span><span style="color:rgb(39,42,216)">5</span><span style="color:rgb(0,0,0)">)</span></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><span class="HOEnZb"><font color="#888888"><div><br></div><div>-- Ross</div></font></span></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>