Kotlin Functions

Functions are concise in Kotlin and can be highly expressive. Default values and named arguments reduce overload noise.

Parameters

fun greet(name: String, title: String = "developer") {
    println("$name is a $title")
}

Named arguments

Named arguments make call sites self-documenting and reduce ambiguity when a function accepts multiple values of similar type.

Lambdas

val sum = { a: Int, b: Int -> a + b }

Extension functions

Extension functions let you add behavior to existing types without subclassing or wrapper objects.

Practice

  1. Write one function with a default parameter.
  2. Call a function using named arguments.
  3. Create one small lambda and one extension function.