2016-04-12 11 views
1

Futureで失敗する可能性のある長いメソッドKleisliを組み合わせたいと思っています。 Kleisliにエフェクトを積み重ねるコードを次に示します。スカラズに既存のコンビネータがあるか?Kleisli [Future、Context、 /]からKleisli [どちらかのT、Context、...]

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です。

答えて

1

あなたは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>) 
関連する問題