nuhkoca
05/04/2022, 5:21 PMnullsLast
with combination of compareBy
but it is not working. Do you know what’s wrong?
I tried;
sortedWith(nullsLast(compareBy { it.price }))
nuhkoca
05/04/2022, 5:25 PMRafael Peratello
05/04/2022, 6:21 PMval collection = listOf(10, null, 2, -1, -3, null, -2, 1)
val sorted = collection
.sortedBy { it }
.groupBy {
when {
it == null -> 1
it < 0 -> 0
else -> 2
}
}
.toSortedMap()
.flatMap { it.value }
Rafael Peratello
05/04/2022, 6:21 PMnuhkoca
05/04/2022, 7:23 PMnullsLast
and so on right? If so, is this a performant way, wdyt?Rafael Peratello
05/04/2022, 8:07 PMnuhkoca
05/04/2022, 9:03 PMnuhkoca
05/05/2022, 12:26 AMRafael Peratello
05/05/2022, 9:04 AMnuhkoca
05/05/2022, 11:41 PM20.30, 45.12, -13.67, null(positive one), null(negative one), -9.45
If I sort from low to high(ascending) output should be;
-13.67, -9.45, null(negative one), 20.30, 45.12, null(positive one)
if in descending order;
45.12, 20.30, null(positive one), -9.45, -13.67, null(negative one)
Rafael Peratello
05/06/2022, 9:29 AM