Recall & Review
beginner
What is a lambda in Kotlin?
A lambda is a small function without a name that can be passed around as a value. It lets you write code blocks that can be used like variables.
Click to reveal answer
beginner
How do lambdas help write functional style code?
Lambdas let you treat functions as data. This means you can pass functions to other functions, return them, and compose them, which is key in functional programming.Click to reveal answer
beginner
What is a real-life example of using a lambda in Kotlin?
Using a lambda to filter a list: val evens = numbers.filter { it % 2 == 0 } filters even numbers using a lambda that checks if a number is even.
Click to reveal answer
intermediate
Why does functional style prefer lambdas over traditional functions?
Lambdas are concise and can be created inline, making code shorter and easier to read. They also support higher-order functions, which are essential in functional programming.
Click to reveal answer
intermediate
What is a higher-order function and how do lambdas relate to it?
A higher-order function takes functions as parameters or returns them. Lambdas are often used as the functions passed to or returned from these higher-order functions.
Click to reveal answer
What is a lambda in Kotlin?
✗ Incorrect
A lambda is an anonymous function that can be passed around as a value.
Which feature of lambdas supports functional programming?
✗ Incorrect
Lambdas can be passed as arguments, enabling higher-order functions, a key part of functional programming.
What does this Kotlin code do? numbers.filter { it > 5 }
✗ Incorrect
The lambda { it > 5 } filters the list to keep numbers greater than 5.
Why are lambdas preferred in functional style over traditional functions?
✗ Incorrect
Lambdas are concise and inline, making functional code cleaner and easier to read.
What is a higher-order function?
✗ Incorrect
Higher-order functions take functions as input or return them, often using lambdas.
Explain how lambdas enable functional programming style in Kotlin.
Think about how functions can be treated like data.
You got /4 concepts.
Describe a simple example of using a lambda in Kotlin to filter a list.
Focus on how the lambda defines the filtering rule.
You got /4 concepts.