FlatMap for nested collections
📖 Scenario: You work at a bookstore that organizes books by genre. Each genre has a list of book titles. You want to create a single list of all book titles from all genres.
🎯 Goal: Build a Kotlin program that uses flatMap to combine nested lists of book titles into one flat list.
📋 What You'll Learn
Create a map called
booksByGenre with genres as keys and lists of book titles as valuesCreate a variable called
allBooks that uses flatMap on booksByGenre.valuesPrint the
allBooks list💡 Why This Matters
🌍 Real World
Bookstores and libraries often organize books by categories. Combining all books into one list helps with searching and displaying all available titles.
💼 Career
Understanding how to flatten nested collections is useful in data processing, backend development, and anywhere you handle grouped data.
Progress0 / 4 steps