Higher-order functions on collections
We briefly touched on this topic in Chapter 1, Getting Started with Kotlin, but before we can discuss streams, let’s make sure that those of us who come from languages that don’t have higher-order functions on collections know what they are, what they do, and what the benefits of using them are.
Higher-order functions on collections are a powerful feature that Kotlin (among other modern programming languages) provides. They simplify the code, make it more readable, and often lead to fewer errors. Let’s discuss some key functions.
We won’t be able to cover all of the functions available on collections, but we’ll cover the most widely used ones.
Mapping elements
The map()
function transforms each element in a collection, potentially into a new type of element. To illustrate this, let’s assume we have a list of letters, and we want to convert them into their corresponding ASCII values.