Skip to content

Commit

Permalink
reactor function change sort
Browse files Browse the repository at this point in the history
  • Loading branch information
AmeerAmjed committed Feb 14, 2024
1 parent a3e5fce commit 8081cf9
Showing 1 changed file with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,17 @@ class ListScreenViewModel {
countries: List<Country>,
sortOrder: SortOrder
): List<Country> {
val comparator: Comparator<String> = if (sortOrder == SortOrder.ASCENDING) {
compareBy { it }
return if (sortOrder == SortOrder.ASCENDING) {
countries.sortedBy { it.name }
} else {
compareByDescending { it }
countries.sortedByDescending { it.name }
}.map { country ->
country.copy(
touristPlaces = country.touristPlaces.sortedBy { it.name }
)
}

return countries.sortedWith(compareBy(comparator) { it.name })
.map { country ->
country.copy(
touristPlaces = country.touristPlaces.sortedWith(compareBy(comparator) { it.name })
)
}

}
fun onAction(actions: ListViewModelActions) {
viewModelScope.launch {
Expand Down

0 comments on commit 8081cf9

Please sign in to comment.