Recall & Review
beginner
What does it mean to return a function from another function in Kotlin?
It means a function can produce another function as its result. This returned function can then be called later, like a recipe that gives you another recipe.
Click to reveal answer
intermediate
How do you declare a function in Kotlin that returns another function?
You specify the return type as a function type. For example, fun outer(): (Int) -> Int means outer returns a function that takes an Int and returns an Int.
Click to reveal answer
beginner
What is a practical example of returning a function from a function?
Creating a multiplier function: a function that returns another function which multiplies input by a fixed number. This helps reuse logic with different multipliers.
Click to reveal answer
intermediate
Can the returned function capture variables from the outer function?
Yes! The returned function can remember variables from the outer function, like a backpack carrying important things for later use. This is called a closure.
Click to reveal answer
beginner
Write a simple Kotlin function that returns a function which adds 5 to its input.
fun addFive(): (Int) -> Int = { x -> x + 5 }
Click to reveal answer
What is the return type of this Kotlin function? fun makeAdder(): (Int) -> Int
✗ Incorrect
The return type (Int) -> Int means the function returns another function that takes an Int and returns an Int.
What keyword is used to define a lambda expression in Kotlin?
✗ Incorrect
Lambdas in Kotlin are defined using curly braces {} with parameters and body inside.
What is a closure in Kotlin functions?
✗ Incorrect
A closure is a function that remembers variables from where it was created.
Which of these is a correct way to return a function from a Kotlin function?
✗ Incorrect
Option B returns a lambda function that doubles its input.
If a function returns another function, how do you call the inner function?
✗ Incorrect
You first call the outer function to get the returned function, then call that function with arguments.
Explain how returning functions from functions works in Kotlin and why it might be useful.
Think about functions as recipes that can give you other recipes.
You got /4 concepts.
Write a Kotlin function that returns a function which adds a given number to its input.
Use a closure to remember the number to add.
You got /3 concepts.