it: The Implicit Parameter
Use the implicit 'it' parameter in single-parameter lambdas.
it: The Implicit Parameter is a free Kotlin Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Kotlin Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
The Implicit it
When a lambda has exactly one parameter, you can omit declaring it and reference it as it. Saves typing for short pipelines.
it in forEach
The classic example: forEach passes each element as it.
fun main() {
listOf(1, 2, 3).forEach { println(it) }
}it in map
Transform each element using it as the input.
fun main() {
val doubled = listOf(1, 2, 3).map { it * 2 }
println(doubled) // [2, 4, 6]
}it in filter
filter keeps elements for which the lambda returns true. it stands for the current element.
fun main() {
val evens = listOf(1, 2, 3, 4, 5).filter { it % 2 == 0 }
println(evens) // [2, 4]
}When NOT to Use it
If the lambda body is non-trivial, name the parameter explicitly. Naming improves clarity over abbreviated it.
fun main() {
val users = listOf("alice", "bob")
// OK
users.forEach { println(it) }
// Clearer with a name when body is bigger
users.forEach { name ->
println("User: $name length=${name.length}")
}
}it in Nested Lambdas
Be careful with nested lambdas: each it binds to the innermost lambda. Naming parameters avoids ambiguity.
fun main() {
val nested = listOf(listOf(1, 2), listOf(3, 4))
// Both lambdas use it — confusing!
nested.forEach { outer ->
outer.forEach { inner ->
println("$outer -> $inner")
}
}
}it with String Methods
Common pattern: filter/map strings using it.
fun main() {
val names = listOf("Alice", "bob", "Charlie")
val upper = names.map { it.uppercase() }
println(upper)
}it with Properties
it.property is a clean way to access fields when chaining operations.
data class Person(val name: String, val age: Int)
fun main() {
val people = listOf(Person("Ana", 20), Person("Ben", 35))
val names = people.map { it.name }
println(names) // [Ana, Ben]
}Predicates with it
Predicates (lambdas returning Boolean) read naturally with it.
fun main() {
val nums = listOf(1, 4, 7, 9)
println(nums.any { it > 5 }) // true
println(nums.all { it > 0 }) // true
println(nums.none { it < 0 }) // true
}Custom Functions with it
Any higher-order function with a single-parameter lambda gives you it automatically.
fun <T> List<T>.firstWhere(predicate: (T) -> Boolean): T? {
for (item in this) if (predicate(item)) return item
return null
}
fun main() {
val n = listOf(3, 8, 4, 5).firstWhere { it > 5 }
println(n) // 8
}it Inside Scope Functions
Some scope functions (let, also) use it as the receiver; others (apply, run) use this. Pick based on whether you want to reference the receiver explicitly.
fun main() {
val name: String? = "Kotlin"
name?.let { println("hello $it") } // it = name
}Quick Check
When can you use it instead of naming a lambda parameter?
Recap
it is the implicit name for the sole parameter of a one-parameter lambda. Use it to shorten short lambdas. Name parameters explicitly when bodies grow or when nesting could cause confusion.
Frequently asked questions
Is the “it: The Implicit Parameter” lesson free?
Yes — the full text of “it: The Implicit Parameter” is free to read here on the web, and the Kotlin Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Kotlin Academy course, upgrade to CoddyKit PRO.
What will I learn in “it: The Implicit Parameter”?
Use the implicit 'it' parameter in single-parameter lambdas. You practise Kotlin Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Kotlin Academy?
No prior experience is required. Kotlin Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “it: The Implicit Parameter” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Kotlin Academy lesson?
Yes. Every Kotlin Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- What Is a Lambda? Syntax and Types
- Passing Lambdas to Functions
- it: The Implicit Parameter
- filter, map, and find on Collections