Kotlin functions, default arguments, lambdas, higher-order functions, collection operations, sequences and scope functions.
40 cards · basic cards · AI-written, checked twice. Edit anything.
- How do you declare a function with parameters and return type in Kotlin?
Show answer
fun functionName(param1: Type, param2: Type): ReturnType { ... }
- How do you define a default parameter value in Kotlin?
Show answer
fun greet(name: String = "World") { ... }
- What is a named argument in Kotlin?
Show answer
Passing arguments by name, e.g., greet(name = "Alice")
- How do you write a single-expression function?
Show answer
fun add(a: Int, b: Int) = a + b
- What does Unit represent as a return type?
Show answer
The absence of a meaningful return value, equivalent to void in Java
- Can you omit the return type in Kotlin if it is obvious?
Show answer
Yes, Kotlin can infer return types in most contexts
- How do you declare a function type in Kotlin?
Show answer
(ParameterType) -> ReturnType, for example (Int, Int) -> String
- What is the basic syntax for a lambda expression?
Show answer
{ param -> expression } or { (param1, param2) -> expression }
- How do you write a lambda with multiple parameters?
Show answer
{ x, y -> x + y } or { (x: Int, y: Int) -> x + y }
- How do you write a lambda with no parameters?
Show answer
{ } or { -> code }
- Define a higher-order function
Show answer
A function that takes another function as a parameter or returns a function
- How do you pass a lambda to a higher-order function?
Show answer
Pass it as an argument, optionally using trailing lambda syntax outside parentheses
- What is the main difference between lambda and anonymous function?
Show answer
Anonymous functions have explicit return types; lambdas use implicit return of the last expression
- What does the let scope function do?
Show answer
Executes a code block with the object as parameter (it) and returns the block result
- What does the run scope function do?
Show answer
Executes a code block with the object as this and returns the block result