<div dir="ltr">In answer to Jonathan:<div>I can define it myself - and did, in the original post. I don't know how common a use-case it is, but it's a small annoyance with switch statements to write 'default: break // this is impossible'. This is a specific scenario where case pattern-matching pattern seemed inadequate, so I pitch it here for more discussion, my thinking being that: perhaps if it's in Core, it can be implemented more efficiently than I've done here. Perhaps there are better choices of characters for the specific operator. Perhaps there's a reason why converting this comparison into an NSComparisonResult isn't already there. I only find out if I ask!</div><div><br></div><div>In answer to Dave:</div><div>That's interesting to hear (and possibly saved everyone the bother of a review!). I wasn't aware it was already a named operator (and in use in other languages, now I've looked it up). I hope it makes it into the schedule, as I'm not sure I know enough to take on that hint!</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Feb 5, 2016 at 12:10 AM, Dave Abrahams via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
on Thu Feb 04 2016, Jonathan Tang <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br>
<br>
> Can't you define this yourself? This worked in a Playground using Swift<br>
> 2.1:<br>
><br>
> enum Ordering {<br>
> case OrderedSame, OrderedAscending, OrderedDescending<br>
> }<br>
><br>
> infix operator <=> {}<br>
> func <=> <T: Comparable>(x: T, y: T) -> Ordering {<br>
> if x < y {<br>
> return .OrderedAscending<br>
> } else if x > y {<br>
> return .OrderedDescending<br>
> } else {<br>
> return .OrderedSame<br>
> }<br>
> }<br>
><br>
> let x = 3<br>
> let y = 4<br>
> switch x <=> y {<br>
> case .OrderedSame:<br>
> print(3)<br>
> case .OrderedAscending:<br>
> print(4) // Executed<br>
> case .OrderedDescending:<br>
> print(5)<br>
> }<br>
<br>
</span>The problem is that the stdlib algorithms don't use this, so sorting,<br>
e.g., an array of arrays of strings ends up being more expensive than<br>
necessary. What you really want is for the "spaceship operator" to be<br>
the primary implementation hook that gets called from the comparison<br>
predicates.<br>
<br>
It's on the agenda for swift 3 to add the spaceship operator, and make<br>
the algorithms use it, and solve the migration problems for old code,<br>
and solve the interop problems with foundation. However, we have a lot<br>
of other work on our hands, and there's always a chance we won't fit it<br>
in the schedule. This could make a great after-starter project for<br>
someone out there who wanted to take it on (hint, hint).<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
-Dave<br>
</font></span><div class="HOEnZb"><div class="h5"><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>
</div></div></blockquote></div><br></div>