2016-04-12 22 views
1

Either başarısız olabilen uzun yöntemlerle çalışan Kleisli'u birleştirmek için, bu etkiyi yığmak zorundayım. İşte Kleisli'deki etkiyi toplamak için ortaya çıkan kod. Scalaz'da mevcut bir birleştirici var mı?Kleisli [Future, Context, /] to Kleisli [EitherT, Bağlam,…]

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

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

Ben başarı f.liftMK[FutureEitherT] olmadan denedim ama maalesef Kleisli tür kurucusu üçüncü tip hala Either olduğunu.

cevap

1

Sen mapK kullanabilirsiniz:

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>) 
İlgili konular