Skip to main content
A lambda parameter in Kotlin is a variable declared within a lambda expression that receives an argument when the underlying function type is invoked. These parameters are defined on the left side of the arrow (->) operator, which separates the parameter list from the execution body.

Explicit Parameter Declaration

By default, lambda parameters are declared explicitly with their names and types.
If the Kotlin compiler can infer the parameter types from the surrounding context (such as the declared function type of the variable), the explicit type declarations can be omitted.

The Implicit it Parameter

When a lambda expression has exactly one parameter, and its type can be inferred by the compiler, Kotlin allows you to omit the parameter declaration and the -> operator entirely. The single parameter is implicitly exposed under the keyword it.

Unused Parameters

If a lambda requires multiple parameters to satisfy a function type signature, but the lambda body does not utilize all of them, the unused parameters can be replaced with an underscore (_). This prevents compiler warnings and explicitly signals to other developers that the parameter is intentionally ignored.

Destructuring Declarations

Lambda parameters support destructuring declarations. If a parameter is a type that provides componentN() operator functions (such as a Data Class, Pair, or Map.Entry), you can destructure the object directly within the parameter list by wrapping the destructured variables in parentheses.
You can also combine destructuring with the unused parameter underscore if you only need specific components of the destructured object:

Default Values Restriction

Unlike standard function parameters, lambda parameters cannot have default values. The Kotlin compiler strictly enforces this rule, meaning all arguments must be provided when the lambda’s underlying function type is invoked. Attempting to assign a default value to a lambda parameter results in a syntax error.

Shadowing

Lambda parameters follow standard lexical scoping rules. If a lambda parameter shares a name with a variable in the enclosing scope, the lambda parameter will shadow the outer variable within the lambda body.
Tired of Poor Kotlin Skills? Fix That With Deep Grasping!Learn More