Transforming Data
The first category we will discuss is transformation functions. A transform function modifies each element of a collection by walking through its contents and modifying each item with a transformer function provided as an argument. The transform function then returns the modified collection.
Two commonly used transform functions are map and flatMap.
map
The map transform function iterates through the collection it is called on and applies its transformer function to each element. The result is a collection of the transformed elements. (Keep in mind that we are talking about the map function, not to be confused with the mapOf function or the Map type.)
Both the map and flatMap functions are commonly used ...
Get Kotlin Programming: The Big Nerd Ranch Guide, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.