Why does Ordered[A] use a compare method instead of reusing compareTo?
- by soc
trait Ordered[A] extends java.lang.Comparable[A] {
def compare(that: A): Int
def < (that: A): Boolean = (this compare that) < 0
def > (that: A): Boolean = (this compare that) > 0
def <= (that: A): Boolean = (this compare that) <= 0
def >= (that: A): Boolean = (this compare that) >= 0
def compareTo(that: A): Int = compare(that)
}
Isn't it a bit useless to have both compare and compareTo?
What is the huge benefit I'm missing here?
If they had just used compareTo I could just had replaced Comparable with Ordered in my code and be done.