Recall & Review
beginner
What is a lambda expression in Kotlin?
A lambda expression is a small block of code that can be passed around and executed later. It is like a mini-function without a name.
Click to reveal answer
beginner
How do you declare a simple lambda that takes two integers and returns their sum?
You write:
{ a: Int, b: Int -> a + b }. This means the lambda takes two integers a and b and returns their sum.Click to reveal answer
beginner
What is the syntax to assign a lambda to a variable in Kotlin?
You assign it like this:
val sum: (Int, Int) -> Int = { a, b -> a + b }. Now sum holds the lambda and you can call it like a function.Click to reveal answer
beginner
How do you call a lambda stored in a variable?
If you have
val greet = { name: String -> "Hello, $name!" }, you call it like this: greet("Alice").Click to reveal answer
intermediate
What is the implicit name for a single parameter in a Kotlin lambda?
If a lambda has only one parameter, you can use
it instead of naming it explicitly. For example: { it * 2 } doubles the input.Click to reveal answer
Which of the following is a correct Kotlin lambda syntax for adding two numbers?
✗ Incorrect
Option A is the correct Kotlin lambda syntax. Options A and D are from other languages, and C is a function, not a lambda.
How do you call a lambda stored in a variable named
multiply with arguments 3 and 4?✗ Incorrect
In Kotlin, you call a lambda like a normal function using parentheses and arguments.
What does the
it keyword represent in a Kotlin lambda?✗ Incorrect
it is used as the name of the single parameter when a lambda has exactly one parameter.Which of these is NOT a valid way to declare a lambda in Kotlin?
✗ Incorrect
Option D uses Python-like syntax which is invalid in Kotlin.
What is the return type of a Kotlin lambda that looks like
{ a: Int, b: Int -> a + b }?✗ Incorrect
The lambda returns the sum of two integers, so its return type is Int.
Explain how to declare and use a lambda in Kotlin that takes one parameter and returns its square.
Think about how to write the lambda and how to call it with a number.
You got /4 concepts.
Describe the difference between a lambda expression and a regular function in Kotlin.
Focus on how lambdas are unnamed and can be stored or passed around easily.
You got /4 concepts.