← Kotlin Programming learning path
Kotlin Programming · Module 4 of 10

Functions and lambdas

Write concise functions and pass behaviour as values.

📖 Key ideas

  1. fun add(a: Int, b: Int): Int = a + b (single-expression function).
  2. Default and named arguments: greet(name = "Asha").
  3. Lambdas: val square = { x: Int -> x * x }.
  4. Higher-order functions take functions as parameters.
  5. 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