https://kotlinlang.org logo
#stdlib
Title
# stdlib
m

Marcin Wisniowski

02/07/2023, 5:09 PM
I have a list of
data class A(val b: B)
, and a
Comparator<B>
, how can I sort the list with this comparator?
sortedWith()
won’t work because the comparator type doesn’t match.
sortedBy()
allows me to select the inner value
b
, but then doesn’t let me choose my comparator.
e

ephemient

02/07/2023, 5:10 PM
Copy code
.sortedWith(compareBy(comparator, A::b))
m

Marcin Wisniowski

02/07/2023, 5:12 PM
Thanks!
2 Views