Exploring concurrent data structures
Now we're familiar with some of the most common higher-order functions on collections, let's combine this knowledge with what we learned in the previous chapter about concurrency primitives in Kotlin to discuss the concurrent data structures Kotlin provides.
The two most essential concurrent data structures are channels and flows. However, before we can discuss them, we need to look at another data structure: sequences. While this data structure is not concurrent itself, it will provide us with a bridge into the concurrent world.
Sequences
Higher-order functions on collections existed in many functional programming languages for a long time. But for Java developers, the higher-order functions for collections first appeared in Java 8 with the introduction of the Stream API.
Despite providing developers with valuable functions such as map()
, filter()
, and some of the others we already discussed, there were two major drawbacks...