Created
June 15, 2018 05:50
-
-
Save dakatsuka/1cd2c2ddcceb56f51760b32136ed23cd to your computer and use it in GitHub Desktop.
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
import scalaz._ | |
import Scalaz._ | |
import scala.concurrent.ExecutionContext.Implicits.global | |
import scala.concurrent.duration.Duration | |
import scala.concurrent.{Await, Future} | |
object Main extends App { | |
val getEitherTFutures1: Seq[EitherT[Future, Throwable, String]] = { | |
Seq( | |
EitherT[Future, Throwable, String](Future.apply(\/-("hoge"))), | |
EitherT[Future, Throwable, String](Future.apply(\/-("hoge"))), | |
EitherT[Future, Throwable, String](Future.apply(\/-("hoge"))) | |
) | |
} | |
val getEitherTFutures2: Seq[EitherT[Future, Throwable, String]] = { | |
Seq( | |
EitherT[Future, Throwable, String](Future.apply(\/-("hoge"))), | |
EitherT[Future, Throwable, String](Future.apply(\/-("hoge"))), | |
EitherT[Future, Throwable, String](Future.apply(-\/(new Exception))) | |
) | |
} | |
val res1 = getEitherTFutures1.toList.sequenceU // EitherT[Future, Throwable, List[String]] | |
val res2 = getEitherTFutures2.toList.sequenceU // EitherT[Future, Throwable, List[String]] | |
Await.result(res1.run.map(_.map(println)), Duration.Inf) // List(hoge, hoge, hoge) | |
Await.result(res2.run.map(e => println(e.left)), Duration.Inf) // -\/(-\/(java.lang.Exception)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment