Internal Iterators

We mostly use for to program external iterators. But internal iteration involves many specialized tools like filter(), map(), flatMap(), reduce(), and so on. Much like the way a professional mechanic uses different specialized tools to fix a car, and doesn’t settle for just a hammer, in functional programming we use a combination of the right tools for different tasks. The Kotlin standard library provides plenty of higher-order functions for internal iteration. We’ll visit some of the most commonly used functions.

filter, map, and reduce

filter(), map(), and reduce() are the three amigos of functional programming; they are fundamental functions used as internal iterators. The filter() function picks certain values from a given ...

Get Programming Kotlin 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.