问题描述
def run(someEither: Either[SomeException,Statement],id: String): EitherT[Future,EncodingException,ResultSet]
def someMethod(...) : zio.IO[SomeException,SomeResult]
run(someEither,data.getorElse("empty")).bimap(
{ e: SomeException => IO.fail(e) },_ => IO.succeed(entity)
)
但是我遇到了关于 Type mismatch
的编译错误 - 需要:IO
,找到:EitherT
。
如何将 EitherT
转换为 zio.IO
?
解决方法
我认为你可以这样做:
import zio._
import cats.data.EitherT
import scala.concurrent.Future
type ResultSet = ???
val eitherT: EitherT[Future,Exception,ResultSet] = ???
val result: IO[Throwable,ResultSet] = ZIO.fromFuture(_ => eitherT.value).flatMap(ZIO.fromEither)