Saiedmomen
08/23/2019, 6:38 PMKFunction
and KSuspendFunction1
? I have imported imported kotlin-reflect
but I have to manually import them and IDE inspection tools like go to declaration and search in path can't find their declarationMarc Knaup
08/23/2019, 6:40 PMSaiedmomen
08/23/2019, 6:50 PMstreetsofboston
08/23/2019, 6:55 PM() -> T
type is not a ‘sub-class’ of (i.e. ‘assignable to’) a suspend () -> T
type… They are entirely separate.var suspendLambda : suspend () -> Int = suspend { 5 }
var lambda : () -> Int = { 5 }
fun main() {
suspendLambda = lambda // ERROR Type Mismatch
}
Saiedmomen
08/23/2019, 7:10 PMstreetsofboston
08/23/2019, 7:14 PM() -> T
to suspend () -> T
by the compiler when needed. (like () -> T
to KFunction<T>
and such…)Marc Knaup
08/23/2019, 7:15 PMsuspend
and non-suspend functions.suspend
function to a non-suspend argument of an inline function:
suspend fun doSomething(transform: suspend (Int) -> String) =
listOf(1,2).map(transform)
Also doesn’t work 😕
But this works:
suspend fun doSomething(transform: suspend (Int) -> String) =
listOf(1, 2).map { transform(it) }
Saiedmomen
08/23/2019, 7:19 PMstreetsofboston
08/23/2019, 7:20 PM