ds3fdfd3
06/29/2021, 1:31 PMeval's
map and flatmap. I have this code but it doesn't compile as doSomething()
can only be called withing coroutine body.
import arrow.core.Eval
import kotlinx.coroutines.runBlocking
fun main(): Unit = runBlocking {
Eval.now(10)
.map { doSomething() }
.value()
}
private suspend fun doSomething(): Int {
println("do something")
return 20
}
simon.vergauwen
06/29/2021, 1:51 PMEval
since it's a deferred execution monad.
What is your use case of combining Eval
with suspend
?ds3fdfd3
06/29/2021, 2:10 PMeval.map { deviceId ->
val user = getUserForDevice(deviceId) //suspend call
doSomethingWithUserAndDevice(user, deviceId)
}
ds3fdfd3
06/29/2021, 2:11 PMsimon.vergauwen
06/30/2021, 7:02 AMEval
around, in this case you'd just want to pass around suspend () -> A
instead.
That way everything is still lazy, and you have full suspend
support without using a data type like Eval
. Which doesn't support this usecase.simon.vergauwen
06/30/2021, 7:02 AMEval
is meant to build pure stacksafe functions that cannot be written with tailrec
.ds3fdfd3
06/30/2021, 9:06 AMEvals
now. It seems better now.