I have a list of Prizes. Each Prize has like 5 pr...
# getting-started
c
I have a list of Prizes. Each Prize has like 5 properties... but if Prize.redeemed = 100... I want to sort those only to the back of the list. So I don't want to sort by redeemed... I just want to put those in the back of the list. How would I do that? I have this... and I'm kinda not sure why it works. I would have thought it would have put these to the front?
prizes.sortedWith(compareBy { it.redeemed == 100 })
e
Copy code
compareBy { it.redeemed == 100 }.compare(a, b)
is
Copy code
naturalOrder<Boolean>().compare(a.redeemed == 100, b.redeemed == 100)
the natural order of booleans is
false < true
👍 1
in any case, sort is O(n log n) while
Copy code
val (redeemed100, redeemedNot1000) = prizes.partition { it.redeemed == 100 }
is O(n)
👍 1