← Kotlin Programming learning pathKotlin Programming · Module 4 of 10
Functions and lambdas
Write concise functions and pass behaviour as values.
📖 Key ideas
- fun add(a: Int, b: Int): Int = a + b (single-expression function).
- Default and named arguments: greet(name = "Asha").
- Lambdas: val square = { x: Int -> x * x }.
- Higher-order functions take functions as parameters.
- it is the implicit name for a single lambda parameter.
💡 Real-life example: A lambda is a sticky note with instructions you hand to someone else to follow later.
Single-expression functionfun f() = expression
Named argumentPass by parameter name
LambdaAnonymous function
itImplicit single parameter