Personally I almost always prefer `followedBy` ove...
# arrow
s
Personally I almost always prefer
followedBy
over
flatMap { _ ->
or
bind
.
😲 1
k
Why?
.bind()
still gives you sequential execution in the
.fx { .. }
block, that’s the idea over it, right?
s
Yes, but that's not used in the snippet.
In most cases there will dependencies between the functions and you'll end up using
fx
but a program could look like this.
Copy code
IO.fx {
   val a = !produceA()
   val b = !sleep(1.seconds).followedBy(consumeA(a))
   b
}
k
hmmm why can’t i just do
Copy code
IO.fx {
  val a = !produceA()
  !sleep(1.seconds)
  val b = !consumeA(a)
  b
}
?
s
Sorry I'm on my phone.
followedBy
serves for a different purpose and provides convenient syntax over plain
bind
or
flatMap
.
That's purely asthetic
k
But both snippets are valid and do the same thing from purity-point-of-view and intention?
s
Absolutely
k
Good, thanks for clarification!
👍 1
s
fun IO<A>.followedBy(fb: IO<A>): IO<B> = flatMap { fb }
And
bind
is
flatMap
with suspension.
👍🏻 1