https://kotlinlang.org logo
Title
h

holgerbrandl

11/16/2017, 1:28 PM
Hmm, I could use
let
, but I actually would like to use a non-extension function on my argument:
(listOf(1,2)).let { (x, y) -> x+y} //works
somefun(listOf(1,2)) { (x, y) -> x+y}  //want that
d

diesieben07

11/16/2017, 1:38 PM
I don't think it exists in the standard library, but you can easily write it yourself:
inline fun <T, R> destructure(value: T, body: (T) -> R): R = body(value)
h

holgerbrandl

11/16/2017, 1:39 PM
Thanks!
Is there a YT ticket for it?
d

diesieben07

11/16/2017, 1:40 PM
I don't know, sorry.
k

karelpeeters

11/16/2017, 1:43 PM
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

diesieben07

11/16/2017, 1:43 PM
Yeah, no "forward type inference" (yet?) 😞
k

karelpeeters

11/16/2017, 1:44 PM
I'm hoping this get's implemented some time, I needed it for some delegates too.