July 2018
Intermediate to advanced
242 pages
8h 6m
English
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), Message("<3", "Sam",
Read now
Unlock full access