What is the `it` in Kotlin lambda body?

it variable is an implicit parameter in lambda.

One other helpful convention is that if a function literal has only one parameter, its declaration may be omitted (along with the ->), and its name will be it:


Here is the kotlin org doc: it: implicit name of a single parameter

for example

ints.filter { value -> value > 0 }

you can simplify it to:

ints.filter { it > 0 }

while you cannot use

ints.filter { value > 0 }

Please refer to the following description.

it: implicit name of a single parameter

It's very common that a lambda expression has only one parameter.

If the compiler can figure the signature out itself, it is allowed not to declare the only parameter and omit ->. The parameter will be implicitly declared under the name it:

ints.filter { it > 0 } // this literal is of type '(it: Int) -> Boolean'

https://kotlinlang.org/docs/reference/lambdas.html#it-implicit-name-of-a-single-parameter