如何提升\/[Error, Int]
进入 EitherT[Future, Error, Int]
使用 point/liftM
语法使得提升在右侧?
我有以下场景
for {
r1 <- f1: EitherT[Future, Error, Int]
r2 <- v: \/[Error, Int]
r3 <- f2: EitherT[Future, Error, Int]
} yield r3
我可以做
v
贴合 EitherT.fromDisjunction[Future]
像这样for {
r1 <- f1
r2 <- EitherT.fromDisjunction[Future](v)
r3 <- f2
} yield r3
或者干脆
for {
r1 <- f1
r2 <- EitherT(Future(v))
r3 <- f2
} yield r3
但是我试图将提升魔法移到
v
的右侧像这样for {
r1 <- f1
r2 <- v.point[Future].liftM[EitherT] // something approximately like this
r3 <- f2
} yield r3
我试过
type Result[F[_], A] = EitherT[F, Error, A]
v.point[Future].liftM[Result]
和
v.point[({ type L[x] = EitherT[Future, Error, x] })#L]
建议 here和 here ,但是这类型到
EitherT[Future, Error, Error \/ Int]
虽然我需要
EitherT[Future, Error, Int]
将提升移到右侧只是为了美观,如
EitherT.fromDisjunction[Future]
工作正常。
最佳答案
只是
r2 <- v.eitherT[Future, Error, Int]
和
import scalaz.{EitherT, \/}
import scalaz.std.scalaFuture._
import scalaz.syntax.eithert._
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
import scala.language.higherKinds
关于scala - 将\/[A, B] 提升到EitherT[Future, A, B],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56741320/