Map transformation
📖 Scenario: You work in a small bookstore. You have a map of book titles and their prices. You want to update the prices by adding a fixed tax to each book.
🎯 Goal: Build a Kotlin program that creates a map of books and prices, sets a tax rate, applies the tax to each price using map transformation, and prints the updated prices.
📋 What You'll Learn
Create a map called
bookPrices with these exact entries: "Kotlin Basics" to 30, "Advanced Kotlin" to 45, "Coroutines Guide" to 40Create a variable called
taxRate and set it to 0.1 (which means 10% tax)Use
mapValues on bookPrices to create a new map called updatedPrices where each price is increased by the tax ratePrint the
updatedPrices map💡 Why This Matters
🌍 Real World
Bookstores and shops often need to update prices by adding taxes or discounts to their product lists.
💼 Career
Understanding map transformations is useful for data processing, pricing algorithms, and working with collections in Kotlin.
Progress0 / 4 steps