Kleisli[Future, Context, \/] 到 Kleisli[EitherT, Context, …]

Kleisli[Future, Context, \/] to Kleisli[EitherT, Context, …]

因为我想结合 Kleisli 可以在长方法上工作 Future 可能会失败 Either,所以我需要叠加效果。这是在 Kleisli 中堆叠效果的结果代码。 scalaz 中是否存在组合器?

type FutureEitherT[A] = EitherT[Future, String, A]

def toKleisliEitherTFromDisjunction[A](f: Kleisli[Future, Context,String \/ A]) = 
  Kleisli[FutureEitherT, Context, A] { ctx => EitherT(f(ctx)) }

我试过没有成功f.liftMK[FutureEitherT],但不幸的是,Kleisli类型构造函数中的第三种类型仍然是Either

你可以使用 mapK:

import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
import scalaz.{\/, EitherT, Kleisli}
import scalaz.std.scalaFuture

type FutureEitherT[A] = EitherT[Future, String, A]

val futureK: Kleisli[Future, Int, String \/ Int] = 
  Kleisli.ask[Future, Int] map (i => \/.right[String, Int](i)))

futureK mapK[FutureEitherT, Int]( EitherT.eitherT )
// scalaz.Kleisli[FutureEitherT,Int,Int] = Kleisli(<function1>)