Hello, I am trying to compose my program using arr...
# arrow
a
Hello, I am trying to compose my program using arrow-fx with suspend functions instead of IO. Is there a possiblity to bind() suspend functions in Either.fx block? Like this:
Copy code
object BusinessError
    object User
    object UserProfile

    suspend fun findUserByName(name : String) : Either<BusinessError, User> = TODO()
    suspend fun getUserProfile(user: User) : Either<BusinessError, UserProfile> = TODO()

    suspend fun getUserProfile(name : String) : Either<BusinessError, UserProfile> = Either.fx {
        val user = findUserByName(name).bind()
        getUserProfile(user).bind()
    }
a
i'm afraid not, for that you would use IO<A>, which can run effects
in the following months we're gonna release IO<E, A> so you could use your domain error models as you do now with Either
👍 2
a
So in that case when I should use
suspend
and when
IO
?
a
they're both equivalent, so if you don't need to do anything special simply use
suspend
for other stuff, like flatmaps, switching threads, performing races, etc then you would use IO
a
what about mixing IO or suspend with Either? should I wait for BIO or it can be DONE nicely with IO?
a
i can be done with IO, but not nicely 😄 You could try, maybe build some private extfuns to hide things like double ops "io.flatmap { either.flatmap..." and whenever IO<E, A> comes, simplify the code
a
What about
Either.fx
inside
IO.fx
?
j
That is only possible without
IO<E, A>
when you use mtl
EitherT
. Its ergonomics arent great but as @aballano said with some ext funcs to hide few annoying things it's decent. Then you can use fx from EitherT and bind any EitherT value, and with
EitherT<ForIO, E, A>
you can lift any IO value into EitherT and bind it inside its fx. It is basically the same as
IO<E, A>
except for performance and ergonomics.
🔝 1
a
@aballano @Jannis thanks for help!
a
Thank you too ☺️