I'm sorting a list of Pair<Int, String>
with this:
list.sortedWith(Comparator.comparingInt<Pair<String, Int>> { it.second }
.thenComparing { it -> it.first })
It seems a bit odd to have to specify { it ->
so is there something more Kotlin-ish I should be using?
Edit: Sorry, I got lost while asking the question: while I did want to know the answers below, what I suppose I was really curious about was why I can't leave out the it ->
:
This compiles:
var c = Comparator
.comparingInt<Pair<String, Int>> { it.second }
.thenComparing { it -> it.first }
This complains with 'unresolved reference it
':
var c = Comparator
.comparingInt<Pair<String, Int>> { it.second }
.thenComparing { it.first }