First up, let's look at the filter() function. The filter() function allows us to provide a lambda, which returns a Boolean that is then used to filter items from a collection.
In this example, we'll use the filter function to print out only items that start with the letter "K":
fun main() {
...
val list = listOf("Kotlin", "Java", "Swift")
list.filter { it.startsWith("K") }
.forEach { println(it) }
}
Notice how we are chaining functions together in this example to first filter the items and then iterate and print them out one by one. This pattern allows us to chain these operations together in more complex ways.