0
0
Kotlinprogramming~30 mins

Testing scope functions and lambdas in Kotlin - Mini Project: Build & Apply

Choose your learning style9 modes available
Testing scope functions and lambdas
📖 Scenario: You are working on a Kotlin program that manages a list of book titles. You want to practice using Kotlin's scope functions and lambdas to manipulate and display this list in a clean and readable way.
🎯 Goal: Build a Kotlin program that creates a list of book titles, uses a scope function to filter and transform the list, and then prints the final result using a lambda expression.
📋 What You'll Learn
Create a list of book titles with exact values
Use a scope function to filter and transform the list
Use a lambda expression to print each book title
Follow exact variable names and function calls as instructed
💡 Why This Matters
🌍 Real World
Scope functions and lambdas help write clean and readable Kotlin code when working with collections and objects.
💼 Career
Understanding scope functions and lambdas is essential for Kotlin developers, especially in Android app development and backend services.
Progress0 / 4 steps
1
Create the list of book titles
Create a val called books and assign it a list containing these exact strings: "Kotlin Basics", "Advanced Kotlin", "Kotlin Coroutines", "Android Development".
Kotlin
Need a hint?

Use listOf() to create the list with the exact book titles.

2
Add a filter threshold variable
Create a val called minLength and set it to 15. This will be used to filter book titles longer than this length.
Kotlin
Need a hint?

Just create a simple integer variable named minLength with value 15.

3
Use a scope function to filter and transform
Use the books list and call run on it. Inside the run lambda, filter the list to keep only titles with length greater than minLength, then map each title to uppercase. Assign the result to a val called filteredBooks.
Kotlin
Need a hint?

Use run on books, then inside the lambda use filter and map with lambdas.

4
Print the filtered book titles
Use filteredBooks.forEach with a lambda that prints each book title exactly as it is.
Kotlin
Need a hint?

Use forEach on filteredBooks and print each item inside the lambda.