Kotlin: What are named lambda arguments used for?
Asked Answered
C

1

10

In Kotlin, it is possible to give lambda arguments names in their definition.

fun example(lambda: (a: Int, b: Int) -> Int)

As you can see, a and b are named in the lambda. I thought this might be really useful information for an IDE, to generate lambdas with the parameter names filled-in.. but at least with IntelliJ the functionality either doesn't exist or works in a way I'm unaware.

So, what are the uses of named lambda arguments? Do they change the compile output in some way? And are there any tricks you can use them for?

Corena answered 26/12, 2016 at 8:42 Comment(0)
M
12

Currently, no language feature uses these names, and, as far as I know, the only thing that does is the generation of lambda templates by the IDE plugin:

enter image description here

Then Tab or Enter, and you will get the lambda with the parameter names declared in the example definition:

enter image description here

Also, see this issue: Make use of named higher order function parameters

Mcalister answered 26/12, 2016 at 9:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.