Kotlin Academy · Lesson

it: The Implicit Parameter

Use the implicit 'it' parameter in single-parameter lambdas.

Lesson 3 of 413 steps

it: The Implicit Parameter is a free Kotlin Academy lesson on CoddyKit. This is lesson 3 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the Kotlin Academy learning path, and your progress syncs across the web and the CoddyKit app. The Kotlin Academy course includes 4 lessons in total.

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.

Free to start

Learn Kotlin with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
51
Lessons
203

Frequently Asked Questions

Is the “it: The Implicit Parameter” lesson free?

Yes — any 3 lessons of the Kotlin Academy learning path, including “it: The Implicit Parameter”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The Kotlin Academy course includes 4 lessons in total.

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, so you can start here or from the beginning and move at your own pace. This is lesson 3 of 4.

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

  1. What Is a Lambda? Syntax and Types
  2. Passing Lambdas to Functions
  3. it: The Implicit Parameter
  4. filter, map, and find on Collections
← Back to Kotlin Academy