Hi, I run into an issue... I have this class: ```d...
# announcements
m
Hi, I run into an issue... I have this class:
Copy code
data 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:
Copy code
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?
z
Write a custom comparator that implements that logic, pass to
sortedWith
.
m
like @Zach Klippenstein (he/him) [MOD] said. use:
compareBy<Hotel>{ ... }.thenBy{ ... }.thenBy{ ... } ...
note that false has precedence over true so you should use descending order if you want true to be before false.