PabloCasia
10/22/2019, 6:06 AMinfix fun Any.fun1(block: () -> Unit) = block.invoke()
infix fun Any.fun2(block: () -> Unit) = block.invoke()
And I'm trying to use variables from first fun on second fun, something like:
fun1 { val item1 = "" } fun2 { val item2 = item1 }
But item1 scope is only fun1
Any suggestions? Aware from declare as a lateinit var outside the functionsjegul
10/22/2019, 6:45 AMinfix fun <T>Any.fun1(block: () -> T) = block.invoke()
infix fun <T>T.fun2(block: T.() -> Unit) = block.invoke(this)
so basically you are returning something from fun1
and use it as receiver to fun2
@PabloCasiaPabloCasia
10/22/2019, 7:40 AMjegul
10/22/2019, 8:27 AMPair
, Triple
, or any other custom data class from fun1
, and then use destructuring declarations on fun2
.karelpeeters
10/22/2019, 8:28 AMfun2
inside the first block somehow, maybe look into something DSL like?streetsofboston
10/22/2019, 11:20 AMPabloCasia
10/23/2019, 3:19 AM