简体   繁体   English

将\ / [A,B]提升为EitherT [未来,A,B]

[英]Lift \/[A, B] into EitherT[Future, A, B]

How to lift \\/[Error, Int] into EitherT[Future, Error, Int] using point/liftM syntax such that lifting is on the right-hand side? 如何使用point/liftM语法将\\/[Error, Int]提升为EitherT[Future, Error, Int] ,以便提升在右侧?

I have the following scenario 我有以下场景

for {
  r1 <- f1: EitherT[Future, Error, Int]
  r2 <- v: \/[Error, Int]
  r3 <- f2: EitherT[Future, Error, Int]
} yield r3

I can make v fit by applying EitherT.fromDisjunction[Future] like so 我可以让v通过应用适合EitherT.fromDisjunction[Future]像这样

for {
  r1 <- f1
  r2 <- EitherT.fromDisjunction[Future](v)
  r3 <- f2
} yield r3

or simply 或者干脆

for {
  r1 <- f1
  r2 <- EitherT(Future(v))
  r3 <- f2
} yield r3

however I am trying to move the lifting magic to the right-hand-side of v like so 但是我试图将提升魔法移动到v的右侧,就像这样

for {
  r1 <- f1
  r2 <- v.point[Future].liftM[EitherT] // something approximately like this
  r3 <- f2
} yield r3

I tried 我试过了

type Result[F[_], A] = EitherT[F, Error, A]
v.point[Future].liftM[Result]

and

v.point[({ type L[x] = EitherT[Future, Error, x] })#L]

suggested here and here , however this types to 这里这里建议,但这种类型

EitherT[Future, Error, Error \/ Int]

whilst I require 虽然我需要

EitherT[Future, Error, Int]

Moving lifting to the right-hand-side is just for aesthetics, as EitherT.fromDisjunction[Future] works fine. 将提升移到右侧只是为了美观,因为EitherT.fromDisjunction[Future]工作得很好。

It's just 只是

r2 <- v.eitherT[Future, Error, Int]

with

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

I am not sure if that exists in scalaz. 我不确定scalaz中是否存在这种情况。 There is no toEitherT[F] on disjunction. toEitherT[F]没有任何toEitherT[F] However it is trivial to add new syntax: 但是添加新语法是微不足道的:

  implicit class EitherLiftSyntax[A, B](val self: A \/ B) extends AnyVal {
    def liftT[M[_]]: EitherT[M, A, B] = EitherT.fromDisjunction[M](self)
  }

As long as you have that in scope, you can say v.liftT[Future] 只要你有这个范围,你可以说v.liftT[Future]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM