0
0
Kotlinprogramming~20 mins

Why lambdas enable functional style in Kotlin - See It in Action

Choose your learning style9 modes available
Why lambdas enable functional style
📖 Scenario: Imagine you are organizing a list of tasks and want to quickly filter and transform them without writing long, repetitive code. Lambdas help you do this in a neat and functional way.
🎯 Goal: You will create a list of tasks, set a filter condition using a lambda, apply a transformation with another lambda, and finally print the results. This shows how lambdas enable a functional style in Kotlin.
📋 What You'll Learn
Create a list of tasks as strings
Create a lambda to filter tasks containing the word 'code'
Create a lambda to transform tasks to uppercase
Use the lambdas with Kotlin's collection functions
Print the final transformed list
💡 Why This Matters
🌍 Real World
Lambdas let you write clean and reusable code for filtering and transforming data, common in apps and backend services.
💼 Career
Understanding lambdas and functional style is important for Kotlin developers to write modern, efficient, and maintainable code.
Progress0 / 4 steps
1
Create a list of tasks
Create a list called tasks with these exact strings: "write code", "review code", "test app", "deploy app"
Kotlin
Need a hint?

Use listOf to create the list with the exact strings.

2
Create a filter lambda
Create a lambda called filterCodeTasks that takes a String and returns true if it contains the word "code"
Kotlin
Need a hint?

Use the lambda syntax with { task -> task.contains("code") }.

3
Create a transform lambda
Create a lambda called toUpperCase that takes a String and returns the uppercase version of it
Kotlin
Need a hint?

Use uppercase() inside the lambda to convert the string.

4
Filter, transform, and print tasks
Use tasks.filter(filterCodeTasks) to get tasks containing "code", then use map(toUpperCase) to convert them to uppercase, and finally print the resulting list with println
Kotlin
Need a hint?

Chain filter and map with the lambdas, then print the list.