Adam Daniel
01/02/2020, 8:57 PMobject 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()
}
aballano
01/02/2020, 9:58 PMaballano
01/02/2020, 9:58 PMAdam Daniel
01/03/2020, 3:33 PMsuspend
and when IO
?aballano
01/03/2020, 4:01 PMsuspend
for other stuff, like flatmaps, switching threads, performing races, etc then you would use IOAdam Daniel
01/03/2020, 4:32 PMaballano
01/03/2020, 4:38 PMAdam Daniel
01/03/2020, 5:17 PMEither.fx
inside IO.fx
?Jannis
01/03/2020, 6:39 PMIO<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.Adam Daniel
01/03/2020, 8:33 PMaballano
01/03/2020, 8:55 PM