Chris Cordero
05/30/2020, 2:41 AMIO.fx
and when you would just use IO
simon.vergauwen
05/30/2020, 9:35 AMIO.fx
is just a DSL to write IO
without having to rely on flatMap
.
Additionally it tries to improve the syntax wherever possible, based on the tricks we can apply in the DSL 🙂CLOVIS
05/30/2020, 10:21 AMsimon.vergauwen
05/30/2020, 10:34 AMraulraja
05/30/2020, 10:57 AMChris Cordero
05/30/2020, 3:44 PMIn the Getting Started docs, there's an example provided where two side effects are composed inside of anis just a DSL to writeIO.fx
without having to rely onIO
.flatMap
fx
object. Is flatMap
being used here in some way?
suspend fun sayHello = println(...)
suspend fun sayGoodbye = println(...)
fun greet(): IO<Unit> =
IO.fx {
!effect { sayHello() }
!effect { sayGoodbye() }
}
CLOVIS
05/30/2020, 3:49 PMSomeMonad.fx {
val (a) = something()
val (b) = somethingElse(a)
}
which, if I understand correctly, is syntax sugar for:
val b = something().flatMap { somethingElse(it) }
simon.vergauwen
05/30/2020, 5:01 PMflatMap
.
It uses suspend
and Continuation
underneath to delegate to flatMap
.Chris Cordero
05/30/2020, 5:05 PMsomethingElse
needed to use the value of a
but in my example the two effects were completely independent of each other.simon.vergauwen
05/30/2020, 5:06 PMeffect { sayHello() }.flatMap { effect { sayGoodbye() } }
.
If you were to change IO.fx
to Concurrent.fx
you can also re-use the same program from RxJava
or Reactor
.