Last active
April 28, 2017 09:34
-
-
Save VlachJosef/c60dd1612b42c3b9b8ccd2ff38a4836e to your computer and use it in GitHub Desktop.
cats.EitherT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package uk.gov.hmrc.bforms.models | |
import org.scalatest.{ FlatSpec, Matchers } | |
import scala.concurrent.Future | |
import scala.concurrent.ExecutionContext.Implicits.global | |
import org.scalatest.concurrent.ScalaFutures | |
import cats.data.EitherT | |
import cats.instances.future._ | |
class EitherTSpec extends FlatSpec with Matchers with ScalaFutures { | |
// final case class EitherT[F[_], A, B](value: F[Either[A, B]]) { ... } | |
"EitherT" should "x" in { | |
val e: Either[String, Int] = Right(1) | |
val f: Future[Int] = Future.successful(123) | |
val et: EitherT[Future, String, Int] = EitherT(Future.successful(e)) | |
val ft: EitherT[Future, String, Int] = EitherT(f.map(i => Right(i): Either[String, Int])) | |
val res = for { | |
e <- et | |
f <- ft | |
} yield e + f | |
println("res " + res.value.futureValue) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment