我需要一个与Future
和\/
配合使用的组合器,我认为EitherT
将有助于删除样板:
经过一番尝试,我已经提出了
type FutureEitherT[A] = EitherT[Future, String, A]
def toKleisliEitherTFromDisjunction[A](f: Kleisli[Future, Context,String \/ A]) = Kleisli[FutureEitherT, Context, A] { ctx => EitherT(f(ctx)) }
def h[A, B](f: Kleisli[Future, Context, String \/ A], g: A => Kleisli[Future, Context, String \/ B]) =
for {
a <- toKleisliEitherTFromDisjunction(f)
b <- toKleisliEitherTFromDisjunction(g(a))
} yield b
答案 0 :(得分:0)
在此answer
的帮助下 type FutureEitherT[A] = EitherT[Future, String, A]
def h[A, B](f: Kleisli[Future, Context, String \/ A], g: A => Kleisli[Future, Context, String \/ B]) =
for {
a <- f.mapK[FutureEitherT, A](EitherT.eitherT)
b <- g(a).mapK[FutureEitherT, B](EitherT.eitherT)
} yield b