`either { }` is already a monad transformer becaus...
# arrow
p
either { }
is already a monad transformer because it allows suspend functions inside 😱
šŸ˜ 1
j
@pakoito I thought transformers work with nested monads. What are the nested monads in this case?
p
IO<Either<E, A>>
is
suspend fun bla(): Either<E, A>
. So it’s nested and not immediately composable
Copy code
bla().flatMap {
  bla() // cannot call suspend functions inside flatMap
}
unless you introduce support inline/suspend on the
either
declaration
so it becomes
EitherT<suspend, E, A>
Copy code
either {
  bla().bind()
  bla().bind()
}
j
Thanks, @pakoito . Were you using
EitherT<suspend, E, A>
to illustrate, or you meant it literally?
Also, can you explain a bit what you mean by "not immediately composable"?
p
to illustrate, yes
Also, can you explain a bit what you mean by ā€œnot immediately composableā€?
Copy code
bla().flatMap {
  bla() // cannot call suspend functions inside flatMap
}
that’s one example
šŸ‘šŸ¾ 1
Copy code
suspend fun somethig() {
  val a: Either<Int, Int> = bla()
  val b: Either<Int, Int> = bla()
}
you don’t have a function to easily sequence one after another and shortcircuit on failure, if you prefer to see it this way
unless you make flatMap support suspend inside, either directly accepting a suspend lambda or via inline (which is a bad hack IMO)
the same way different monad types are not immediately composable, i.e. Either with Option, or IO with Observable, you cannot combine Either with Suspend
or Suspend with Compose for that matter šŸ˜›
j
Thanks @pakoito
unless you make flatMap support suspend inside, either directly accepting a suspend lambda or via inline (which is a bad hack IMO)
Is this referring to making
flatMap
inline?