Can we use monad comprehensions inside coroutines?...
# arrow
m
Can we use monad comprehensions inside coroutines? Can Kotlin support this, at all, at the moment?
r
Hi @melatonina Monad comprehensions are based on suspension not coroutines from the kotlinX Coroutines library, but Arrow does have integrations to use it alongside the KotlinX Coroutines Library. //cc @aballano
👍 1
m
Thank you very much, Raul! I'm going to use this soon on an Android app and its supporting cloud service.
👍 1
r
@Jorge Castillo, @aballano, @danieeh and @simon.vergauwen have better opinions than me as to how Arrow is integrated in Android with the lifecycle, observers etc and they may be able to point out better literature than just the link
j
Hey! Yep you can go from any suspend code to IO with IO.effect { suspendComputation() } and from there use IO.fx for comprehensions over all your IO calls
👍 1
For Android we've got some syntax right about to release with a post that will showcase how to scope any IO tasks to a coroutine scope for automatic cancellation within the scope
👍 1
m
Thanks, Jorge.
Is there any difference when using Either.fx, instead?
s
Either
does not support any effects explicitely, so you can not use it for anything like concurreny, parallelism etc
👍 1
Either.fx
uses
suspend
&
kotlin.coroutines.Continuation
from the std to provide `bind`/`!` syntax for monad comphrensions. It’s completely unrelated to KotlinX Coroutines or concurrency/parallelism.
👍 1
m
Thanks for you patience, Simon and Jorge and Raul.
👍 1
s
You’re very welcome @melanchroes! 🙂