Dominaezzz
06/17/2021, 9:48 AMcompareBy
requires to much type info up front, at least the overload that takes a selector.ilya.gorbunov
06/17/2021, 12:23 PMcompareBy
?Dominaezzz
06/17/2021, 1:13 PMList<Pair<String, String?>>
Right now I have to do this.
val currentComparator = compareBy<Pair<String, String?>, String?>(nullsLast()) { it.second }
.thenBy { it.first }
Dominaezzz
06/17/2021, 1:13 PMobject NoopComparator : Comparator<Nothing> {
override fun compare(p0: Nothing?, p1: Nothing?): Int {
return 0
}
}
fun <T> noop(): Comparator<T> {
return NoopComparator as Comparator<T>
}
Dominaezzz
06/17/2021, 1:14 PMval idealComparator = noop<Pair<String, String?>>()
.thenBy(nullsLast()) { it.second }
.thenBy { it.first }
Dominaezzz
06/17/2021, 1:15 PMval alternativeComparator = compareBy<Pair<String, String?>> {""}
.thenBy(nullsLast()) { it.second }
.thenBy { it.first }
Dominaezzz
06/17/2021, 1:16 PMNoopComparator
to my codebase when I could just add another type param. But I guess that's besides the point now.Dominaezzz
06/17/2021, 1:17 PMnoop
name)ephemient
06/17/2021, 3:15 PMcompareBy(nullsLast()) { it: Pair<String, String?> -> it.second }
compareBy(nullsLast(), Pair<String, String?>::second)
still a bit wordy but less than your current?Dominaezzz
06/17/2021, 3:39 PM