Replies: 2 comments 1 reply
-
|
Hey @clojj, Thanks for opening this discussion!
This is actually provided by the Kotlin Standard Library here and you can use it to run any val program: suspend () -> Int = suspend { 10 }
program.startCoroutine(Continuation(EmptyCoroutineContext) { result ->
val i = result.getOrNull() // 10
})But this is considered to bit a bit low-level, and when working with a frameworks there are other options.
The idea is that just like you cannot execute suspend fun program(): Int = 10
suspend fun program2(): Either<Throwable, Int> =
Either.catch { program() }
suspend fun program3(): Int =
Either.catch { program() }.getOrElse { 0 }The cool thing about |
Beta Was this translation helpful? Give feedback.
-
|
Closing since the relevant line has been added to the docs |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I think this is an important part in the documentation:
https://github.com/arrow-kt/arrow/tree/master/arrow-site/docs/docs/io#safety--purity--referential-transparency
Maybe it is possible to expand this part with at least one concrete example of
f: (Result<A>) -> Unitto run asuspend () -> AprogramReferring respectively to
Beta Was this translation helpful? Give feedback.
All reactions