我怎样才能重构这个以使用Monad变换器和理解?

时间:2017-05-07 10:46:34

标签: scala monad-transformers scala-cats

如何重构此代码以使用猫EitherT,ReaderT(?)和Future,这样我就可以摆脱嵌套并以for-comprehension样式编写它?

import scala.concurrent.Future

trait Foo[A, B, C, D, E] {

  def bar(f: A => Future[B]): Future[B]

  def baz: Future[Either[E, Future[C]]]

  def qux(f: C => B)(a: A): B

  def quz(e: E): Future[B]

  def corge(c: C): B

  def quux: Future[B] =
    bar { a =>
      baz flatMap {
        case Left(e) => quz(e)
        case Right(x) => x map { _ =>
          qux(c => corge(c))(a)
        }
      }
    }
}

0 个答案:

没有答案