Mark Buikema
06/23/2020, 1:59 PMdata class Hotel(
val id: String,
val openStatus: OpenStatus //OpenStatus is an enum with values OPEN, PREORDER, CLOSED
val favorite: Boolean
val sortingValue: Int
)
Now I have a list of hotels. I want to sort the list in a way that it results in this:
Open/preorder section (openStatus == OPEN || openStatus == PREORDER)
Favorites
Open
Sorted by sortingvalue
Preorder
Sorted by sortingvalue
Non-favorites
Open
Sorted by sortingvalue
Preorder
Sorted by sortingvalue
Closed section (openStatus == CLOSED)
Favorites
Sorted by sortingvalue
Non-favorites
Sorted by sortingvalue
What would be the best way to achieve this sorting behavior?Zach Klippenstein (he/him) [MOD]
06/23/2020, 2:04 PMsortedWith
.Michael de Kaste
06/23/2020, 2:22 PMcompareBy<Hotel>{ ... }.thenBy{ ... }.thenBy{ ... } ...
note that false has precedence over true so you should use descending order if you want true to be before false.