Hmm, I could use `let`, but I actually would like ...
# getting-started
h
Hmm, I could use
let
, but I actually would like to use a non-extension function on my argument:
Copy code
(listOf(1,2)).let { (x, y) -> x+y} //works
somefun(listOf(1,2)) { (x, y) -> x+y}  //want that
d
I don't think it exists in the standard library, but you can easily write it yourself:
Copy code
inline fun <T, R> destructure(value: T, body: (T) -> R): R = body(value)
h
Thanks!
Is there a YT ticket for it?
d
I don't know, sorry.
k
Last time this came up "is there a variant of run that calls a lambda with a given parameter?" the solution was to just call it yourself with
{ ... } (...)
, but this doesn't work:
{(a, b) -> a+b}(listOf(1,2))
You'd need to specify the types explicitly.
d
Yeah, no "forward type inference" (yet?) 😞
k
I'm hoping this get's implemented some time, I needed it for some delegates too.