Jire
Jire

Reputation: 10290

Kotlin: What are named lambda arguments used for?

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?

Upvotes: 10

Views: 1072

Answers (1)

hotkey
hotkey

Reputation: 147971

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

Upvotes: 12

Related Questions