From the course: Build Spring Boot Apps with the Kotlin Programming Language

Unlock this course with a free trial

Join today to access over 22,400 courses taught by industry experts.

filter and flatMap

filter and flatMap

- So the map transformation will create a one to one mapping between the starting list and the ending list. We've already seen the filter method. This creates a subset of the list. But again all we need to worry about is providing some kind of meaningful function to do the filtering. So let's say we want to get just a list of those colors that start with the letter B. We can do something like val colors starting with B. We start with our list of colors. We are calling the filter function and we need to provide in some kind of function here that says its color starting with the letter B. That's going to be very simple. It's going to be it. The default parameter dot starts with and then the letter B. That should give us a small list of colors. Let's check it does. So let's print out the list of colors in our new color starting with B list. And we'll just run that and hopefully that means we'll get at the bottom here just blue and black. And we do. So filter is another example of a…

Contents