Lauren Yew
12/17/2020, 4:10 PMclass Builder (
private val function: (suspend () -> String) //Don't want to force Builder to have to provide a no argument function
)
Context: I used to be able to do this in RxJava with a Single. Moving to Coroutines / Flow.Vampire
12/17/2020, 4:15 PMfunction
if you don't know how many arguments it will have?Lauren Yew
12/17/2020, 4:15 PMvararg
in other functions...Lauren Yew
12/17/2020, 4:17 PMLauren Yew
12/17/2020, 4:17 PMLauren Yew
12/17/2020, 4:18 PMval builder = Builder(::exampleFunc)
func exampleFunc(x: Int): String {...}
Vampire
12/17/2020, 4:21 PMx
?Vampire
12/17/2020, 4:21 PMLauren Yew
12/17/2020, 4:21 PMVampire
12/17/2020, 4:21 PMLauren Yew
12/17/2020, 4:22 PMVampire
12/17/2020, 4:23 PMclass Builder(
private val function: suspend () -> String
)
fun exampleFunc(x: Int): String = ""
val builder = Builder { exampleFunc(1) }
Vampire
12/17/2020, 4:24 PMLauren Yew
12/17/2020, 4:25 PMVampire
12/17/2020, 4:25 PMYoussef Shoaib [MOD]
12/18/2020, 4:35 PMclass Builder<R, T: KFunction<R>>(private val func: T) {
inline fun callFunction(caller: T.() -> R) = func.caller()
}