ilya.gorbunov
03/09/2016, 3:29 PMThis interface imposes a total ordering on the objects of each class that implements it
voddan
03/09/2016, 3:29 PMInterface
voddan
03/09/2016, 3:29 PMilya.gorbunov
03/09/2016, 3:31 PMvoddan
03/09/2016, 3:34 PMcompareTo
while keeping the contract of Comparable
, since it does not let anybody to use it in the wrong way (ei sorting)voddan
03/09/2016, 3:35 PMilya.gorbunov
03/09/2016, 3:41 PMcompareTo
and related operators usually come from implementation of Comparable
— he could make wrong conclusions about the contract.
If I ultimately need to have such operator overloads I would scope them as narrow as possible, for example with member-extensions:
object MyPartialOrderComparator: Comparator<Class<*>> {
override fun compare(p0: Class<*>?, p1: Class<*>?): Int = TODO()
operator fun Class<*>.compareTo(other: Class<*>): Int = compare(this, other)
}
fun partialOrderUsage(c1: Class<*>, c2: Class<*>): Boolean {
with (MyPartialOrderComparator) {
return (c1 < c2) || (c1 > c2)
}
}
Here a reader would have more chances to notice that it's not usual greater than
and less than
operators and that the MyPartialOrderComparator
could be somehow involved in semantics of comparisons.voddan
03/09/2016, 3:47 PMvoddan
03/09/2016, 3:47 PMvoddan
03/09/2016, 3:48 PMmplatvoet
03/09/2016, 6:41 PMmplatvoet
03/09/2016, 6:41 PMmplatvoet
03/09/2016, 6:41 PMilya.gorbunov
03/09/2016, 6:49 PMbashor
03/09/2016, 6:51 PMmplatvoet
03/09/2016, 6:53 PMmplatvoet
03/09/2016, 6:54 PMbashor
03/09/2016, 6:58 PMbashor
03/09/2016, 6:58 PMmplatvoet
03/09/2016, 7:01 PMbashor
03/09/2016, 7:01 PMmplatvoet
03/09/2016, 7:02 PMjw
03/10/2016, 8:20 PMmerge
function on Map that uses a provided function on collisions?jw
03/10/2016, 8:20 PMjw
03/10/2016, 8:21 PMfun <K, V> Map<K, V> merge(other: Map<K, V>, combineFunc: (V, V) -> V) = ...
jw
03/10/2016, 8:22 PMcedric
03/10/2016, 8:23 PMjw
03/10/2016, 8:23 PMjw
03/10/2016, 8:23 PMcedric
03/10/2016, 8:23 PMmap: (K) -> T
)