This PR deprecates Order since Kotlin, and Kotlin's Std doesn't take Order into account nor does Kotlin have the power to automatically derive or inject Order anywhere. This makes Order very cumbersome to work with, see Tuple10Order.kt
Another issue with Order is that non of the data types, or collections out there take Order into account. For example SortedMap doesn't work with Order, but still relies on the existing Comparable or Comparator type.
Sadly when implementing operator fun A.compareTo it still doesn't make the type AComparable<A>.
It's easy to derive Comparator in case all involved types are Comparable<A> for example, val x: Comparator<Either<Int, Stringn>> = Comparator { a, b -> a.compareTo(b) }.
Usage examples:
2.right() <= 3.right() // <=, and other comparing symbols enabled through `compareTo`
val x: List<Either<String, Int>> = listOf(3.right(), 1.right(), 2.right())
x.sortedWith(Either<String, Int>::compareTo) // Derive `Comparator` from `compareTo`
maxOf(2.right(), 3.right(), Either<String, Int>::compareTo)
minOf(2.right(), 3.right(), Either<String, Int>::compareTo)
sort(2.right(), 3.right(), 1,right(), -5.right(), comparator = Either<String, Int>::compareTo)
...
We could also expose Either.comparator from Either's companion but it's almost as easy as just using a lambda reference to derive it fromcompareTo since Comparator is a @FunctionalInterface interface.
This PR deprecates
Order
since Kotlin, and Kotlin's Std doesn't takeOrder
into account nor does Kotlin have the power to automatically derive or injectOrder
anywhere. This makesOrder
very cumbersome to work with, seeTuple10Order.kt
Another issue with
Order
is that non of the data types, or collections out there takeOrder
into account. For exampleSortedMap
doesn't work withOrder
, but still relies on the existingComparable
orComparator
type.Sadly when implementing
operator fun A.compareTo
it still doesn't make the typeA
Comparable<A>
. It's easy to deriveComparator
in case all involved types areComparable<A>
for example,val x: Comparator<Either<Int, Stringn>> = Comparator { a, b -> a.compareTo(b) }
.Usage examples:
We could also expose
Either.comparator
fromEither
's companion but it's almost as easy as just using a lambda reference to derive it fromcompareTo
sinceComparator
is a@FunctionalInterface
interface.