Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>So now I've tried to use Scalaz Either (which is a right biased Either compared to the neutral scala Either) and the Monad Transformer EitherT and it seems it does exactly what I want. Thanks to Huw and especially Lars Hupel for hinting me in the right direction.</p> <p>Here is working a sample for Twitter futures and Scalaz Either and EitherT:</p> <pre><code>import com.twitter.util.{Await, Future} import scalaz.{Monad, Functor, EitherT, \/} import scalaz.syntax.ToIdOps object EitherTest extends App with ToIdOps{ // make Twitter futures work with EitherT implicit val FutureFunctor = new Functor[Future] { def map[A, B](a: Future[A])(f: A =&gt; B): Future[B] = a map f } implicit val FutureMonad = new Monad[Future] { def point[A](a: =&gt; A): Future[A] = Future(a) def bind[A, B](fa: Future[A])(f: (A) =&gt; Future[B]): Future[B] = fa flatMap f } // The example begins here: case class InvalidInfo(error: String) case class Response(msg: String) class ComponentA { def foo(fail: Boolean): Future[\/[InvalidInfo, Response]] = { if(fail) Future(InvalidInfo("Error A").left) else Future(Response("ComponentA Success").right) } } class ComponentB { def bar(fail: Boolean): Future[\/[InvalidInfo, Response]] = { if(fail) Future(InvalidInfo("Error B").left) else Future(Response("ComponentB Success").right) } } val a = new ComponentA val b = new ComponentB val result = for { resultA &lt;- EitherT(a.foo(false)) resultB &lt;- EitherT(b.bar(false)) } yield (resultA, resultB) println(Await.result(result.run)) } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload