val listPlans: List<Plan> = newPlans.mapTry {
it.data.map {
Plan(it.id, it.name, it.phone, it.desc, it.email)
}.toList()
}
Kotlin newbie writing code and IntelliJ highglights it in the Plan(it.id, it.name, it.phone, it.desc, it.email)
and says that implicit parameter of enclosing lambda is shadowed.
Is it ok to leave this as it is? If not, what can I replace it with?
You have nested lambdas, so "it" will represent the implicit parameter of the innermost lambda. This warning is mainly for readability purposes and avoiding confusion because the meaning of "it" gets more unclear as you nest more lambdas. I recommend you to specify lambda parameters explicitly for nested lambdas:
val listPlans: List<Plan> = newPlans.mapTry { plan ->
plan.data.map {
Plan(it.id, it.name, it.phone, it.desc, it.email)
}.toList()
}
or
val listPlans: List<Plan> = newPlans.mapTry {
it.data.map { planData ->
Plan(planData.id, planData.name, planData.phone, planData.desc, planData.email)
}.toList()
}
or both:
val listPlans: List<Plan> = newPlans.mapTry { plan ->
plan.data.map { planData ->
Plan(planData.id, planData.name, planData.phone, planData.desc, planData.email)
}.toList()
}
It is worth to point out that this is one of the reasons why JetBrains team is planning to remove "it" functionality
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With