Stage 1 · Lesson 3 of 9
Functions, lambdas and extensions
support default and named arguments. That is why functions can take many optional parameters. A function with one expression can be written in one line: fun double(x: Int) = x * 2.
, small unnamed functions, are everywhere. When the last parameter is a function, you pass it after the brackets, as in button.setOnClick { save() } or list.filter { it.done }. Here it is the name of the single parameter.
Higher-order functions take or return other functions. Extension functions add methods to existing types, such as fun String.initials(). Scope functions (let, apply, also, run, with) are handy but easy to overuse.
Common trapchaining so many scope functions that nobody can tell what it refers to.
A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock
Resources for this stage
Start with· follow one of these
- GuideFreeKotlin Documentation
JetBrains
Start with the Kotlin tour, then the null safety and coroutines basics pages
- CourseFreeAndroid Basics with Compose
Google · Beginner
The Kotlin pathways in Units 1 to 3 teach the language with practice sets