zceejkr
11/09/2019, 7:09 PMval lam = { (a, b) ->
println("$a, $b")
}
lam(Pair(5, 3))
prints 5, undefined
But:
val lam = { pair ->
val a = pair.first
val b = pair.second
println("$a, $b")
}
lam(Pair(5, 3))
prints 5, 3
anton.bannykh
11/12/2019, 10:10 AMlam
? Neither snippets should compile in isolation, because the compiler cannot infer the parameter types.
The following should work though:
val lam: (Pair<Int, Int>) -> Unit = { (a, b) ->
println("$a, $b")
}
lam(Pair(5, 3))
Could you please try
val lam = { pair ->
val a = pair.component1()
val b = pair.component2()
println("$a, $b")
}
lam(Pair(5, 3))
If it fails then destructuring is not the issue here. If it workanton.bannykh
11/12/2019, 10:11 AMzceejkr
11/12/2019, 10:21 AManton.bannykh
11/14/2019, 4:13 PMcomponentN
variant, because that's what destructuring delegates to. If it fails it's much easier to debug. If it doesn't, then it might be a compiler issue.