In this recipe, we are going to explore the support for sorting collections' elements by their properties.
Sorting data with custom comparators
Getting started
Let's assume we are dealing with the two collections of the Message type declared as follows:
data class Message(val text: String,
val sender: String,
val receiver: String,
val time: Instant = Instant.now())
These are provided by the allMessages variable:
val sentMessages = listOf(
Message("I'm programming in Kotlin, of course",
"Samuel",
"Agat",
Instant.parse("2018-12-18T10:13:35Z")),
Message("...