由于我想将工作在长方法( Kleisli )上的Future (可能会导致Either失败)结合在一起,所以我需要叠加效果。下面是在Kleisli中叠加效果的结果代码。有没有一个现有的组合器在斯卡拉兹?
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。
发布于 2016-04-12 10:13:00
你可以用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>)https://stackoverflow.com/questions/36568726
复制相似问题