От: | Serginio1 | https://habrahabr.ru/users/serginio1/topics/ | |
Дата: | 12.11.20 18:03 | ||
Оценка: |
Q>Q>it: implicit name of a single parameter
Q>It's very common that a lambda expression has only one parameter.
Q>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:
Q>Q>ints.filter { it > 0 } // this literal is of type '(it: Int) -> Boolean' Q>
Q>— https://kotlinlang.org/docs/reference/lambdas.html#it-implicit-name-of-a-single-parameter
Q>Passing trailing lambdas
Q>In Kotlin, there is a convention: if the last parameter of a function is a function, then a lambda expression passed as the corresponding argument can be placed outside the parentheses:
Q>Q>val product = items.fold(1) { acc, e -> acc * e } Q>
Q>Such syntax is also known as trailing lambda.
Q>If the lambda is the only argument to that call, the parentheses can be omitted entirely:
Q>Q>run { println("...") } Q>
Q>— https://kotlinlang.org/docs/reference/lambdas.html#passing-a-lambda-to-the-last-parameter