Skip to content

Instantly share code, notes, and snippets.

@gigiigig
Last active August 29, 2015 14:07
Show Gist options
  • Save gigiigig/06f7af4725df55cbe257 to your computer and use it in GitHub Desktop.
Save gigiigig/06f7af4725df55cbe257 to your computer and use it in GitHub Desktop.
Make EitherT work with Validation
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
import scalaz._
import Scalaz._
object console extends App {
val v1: Future[Validation[String, Int]] = 1.success[String].point[Future]
val v2: Future[Validation[String, Int]] = 1.success[String].point[Future]
implicit def etv[G[_], A, B](e: G[\/[A, B]])(implicit F : Functor[G]): G[Validation[A, B]] = {
F.map(e)(_.validation)
}
implicit def vte[G[_], A, B](v: G[Validation[A, B]])(implicit F : Functor[G]): G[\/[A, B]] = {
F.map(v)(_.disjunction)
}
val validation: Future[Validation[String, Int]] =
(for {
val1 <- EitherT[Future ,String, Int](v1)
val2 <- EitherT[Future ,String, Int](v2)
} yield val1 + val2).run
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment