[英]Kleisli[Future, Context, \/] to Kleisli[EitherT, Context, …]
As I want to combine Kleisli
that works on long methods Future
that can fail Either
, I need to stack the effect. 当我想结合
Kleisli
上长方法适用Future
可能出现故障Either
,我需要堆的效果。 Here is the resulting code to stack the effect in the Kleisli. 这是将效果叠加在Kleisli中的结果代码。 Is there an existing combinator in scalaz ?
scalaz中是否有现有的combinator?
type FutureEitherT[A] = EitherT[Future, String, A]
def toKleisliEitherTFromDisjunction[A](f: Kleisli[Future, Context,String \/ A]) =
Kleisli[FutureEitherT, Context, A] { ctx => EitherT(f(ctx)) }
I've tried without success f.liftMK[FutureEitherT]
, but unfortunately, the third types in the Kleisli
type constructor is still an Either
. 我试过
f.liftMK[FutureEitherT]
没有成功,但不幸的是, Kleisli
类型构造函数中的第三个类型仍然是Either
。
You could use mapK
: 您可以使用
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>)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.