Travis Griggs
08/25/2021, 8:26 PMoverride fun compareTo(other: ValveSpan): Int {
val fields = listOf(ValveSpan::begin, ValveSpan::end, ValveSpan::userTitle)
val comparisons = fields.asSequence().map { field -> field(this).compareTo(field(other)) }
return comparisons.firstOrNull { n -> n != 0 } ?: 0
}
Basically an arbitrary number of accessors, work through them lazily until i get to a non zero return and return that. But the compiler complains because:
Type mismatch.
Required: {Duration & String}
Found: {Comparable{Duration & String}> & Serializable}
my begin and end accessors do indeed return Durations and the userTitle does indeed return a String. I'm not entirely clear on what the compiler is not happy about here though. it seems like its figuring it out kind of, but not all the way. or there's some stupid syntax error that will only finally embarssingly occur to me finally after pressing send...ephemient
08/25/2021, 8:38 PMoverride fun compareTo(other: ValueSpan): Int =
compareValuesBy(this, other, ValueSpan::begin, ValueSpan::end, ValueSpan::userTitle)
CLOVIS
08/25/2021, 9:21 PM<in T>
, so Comparable<Any>
is not a super type of Comparable<Duration>
etc.Travis Griggs
08/25/2021, 10:17 PM