From the course: Intermediate Kotlin for Android Developers
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Collection operators: Aggregating
From the course: Intermediate Kotlin for Android Developers
Collection operators: Aggregating
- [Instructor] Beyond simple filtering and mapping of your collection data, Kotlin provides several functions which allow you to aggregate your data as well. Let's take a look at the aggregate operations file so that we can get some deeper insight into our collection of planets. So our first function is "fewestMoons" here on line 11. And since each planet has a given number of known moons, we want to get the smallest number. Now we can do this by first getting the list which contains the number of known moons only. So we'll just create a variable, we'll set it equal to "moons", we'll get our list of planets and then we'll call the map function on it and let's provide our "Planet", "knownMoons" and the member reference. Perfect. So let's come here on line 16 and print this list out first. And then we can duplicate that and we're going to call the min function in order to get the smallest number of known moons. So if we run this test, what we would hope to see is first our list of all…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.