What is the use of providing named parameters in l...
# getting-started
r
What is the use of providing named parameters in lambda types, this doesn't get used instead of 'it' so what is the actual use here, am i missing something?
l
Afaik, when you call a function with this kind of lambda, IDEA will provide you with this defined name instead of
it
or the class name. Also it's more obvious what the parameter is, so it's more like a normal function.
r
My IDEA doesn't appear to do this just the same it parameter
l
you can try to first declare the parameter names
or try with two or more parameters and call it
n
You can provide multiple parameters
r
im aware i can provide multiple params, but no matter what i provide it seems to always be it or if i declare the params in the lambda manually it would be meaningless in the first place, i suppose it seems like its only there for readability.
l
kotlin always give you a choice of it
n
it will be ‘it’ by default, yes. But it will not compile if you do not explicitly set the names if you have more than 1, because compiler will be confused
So if I have 1 parameter, then compiler will give you by default ‘it’
r
it wouldn't compile even with the named, I'm not asking about lambdas in general, im experienced in kotlin im just asking specifically about the optional naming which by what i can see is only for readability
n
it doesn’t compile because you have 2 named parameters, and you have to explicitly name them. However if you have 1 parameter then it will compile. Although I agree that it is mostly for readability, but then kotlin compiler should make that variable the name you named, and not ‘it’
r
Would you mind posting snippets rather than screenshots, unless it's specifically IDE related?