, . -, , , , ( EitherT[Future, Int, ?]), , , , , .
, , , , , , . :
import scalaz._, Scalaz._
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
def one(a: String): Disjunction[Int, String] = (a == "one").either("one").or(2)
def two(a: String): Disjunction[Int, String] = (a == "two").either("two").or(3)
def three(a: String): EitherT[Future, Int, String] = EitherT(
Future(a == "three").map(_.either("three").or(4))
)
def validate(a: String) = for {
e1 <- EitherT.fromDisjunction[Future](one(a))
e2 <- EitherT.fromDisjunction[Future](two(a))
e3 <- three(a)
} yield (e1 |+| e2 |+| e3)
:
scala> validate("one").run.foreach(println)
-\/(3)
scala> validate("x").run.foreach(println)
-\/(2)
- Future, for -, EitherT[Future, String, A] .liftM[EitherT[?[_], String, ?]].
( , , , , ( "one", "two" "three" ), .)
, : , Future[Disjunction[Int, ?]] EitherT[Future, Int, ?] .. Future - ( FutureT ), , , .