Why doesn't Kotlin provide a spaceship operator


#1

So Kotlin allows comparing to objects of type Comparable using <, <=, >, and >=.

This is really nice and much better than checking the return value of the compareTo() function.

But why is there no spaceship operator <=> like in Groovy?

o1 <=> o2  // equivalent to o1.compareTo(o2)

I understand that this is a much rarer use case than using the other operators but I think it would be more consistent (and as a Groovy developer I would expect it to work ;)).


#2

Well, the use cases for this are so few that it's not worth the effort (you can always use compareTo, and it is even more readable, because you don't have to remember the weird symbol's meaning). You mention consistency, but all consistency I can see here is consistency with Groovy, which is not a goal for us :)


#3

You are correct, the syntax is weird and there aren't too many use cases. Thank you for your answer and keep up the awesome work :).