🐦 Kotlin Beginner

What is a lambda expression in Kotlin?

Answer

A lambda expression is an anonymous function that can be passed as a value. The syntax is { parameters -> body }. Example: val double = { x: Int -> x * 2 }. If the lambda has a single parameter, you can omit it and use the implicit it name: list.filter { it > 5 }. If the lambda is the last argument of a function, it can be placed outside the parentheses (trailing lambda syntax). Lambdas are used extensively with higher-order functions for collection processing, event handling, and callbacks.