Filtering is one of the most common programming challenges in the data processing field. In this recipe, we are going to explore the standard library's built-in extension functions that provide an easy way to filter the Iterable data types. Let's assume we have the following Message class declaration:
data class Message(val text: String,
val sender: String,
val receiver: String,
val folder: Folder = Folder.INBOX,
val timestamp: Instant = Instant.now())
enum class Folder { INBOX, SENT }
The getMessages() function returns the following data:
fun getMessages() = mutableListOf(
Message("Je t'aime", "Agat", "Sam", Folder.INBOX),
Message("Hey, Let's go climbing tomorrow", "Stefan", "Sam", Folder.INBOX...