Created
January 24, 2014 00:22
-
-
Save ceedubs/8589661 to your computer and use it in GitHub Desktop.
Defining type alias ErrorsOrT to use liftM on EitherT instances without using a type lambda
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
scala> import scalaz.syntax.id._ // for .right | |
import scalaz.syntax.id._ | |
scala> import scalaz.EitherT | |
import scalaz.EitherT | |
scala> import scalaz.NonEmptyList | |
import scalaz.NonEmptyList | |
scala> import scala.concurrent.Future | |
import scala.concurrent.Future | |
scala> import scalaz.syntax.monad._ // for liftM | |
import scalaz.syntax.monad._ | |
scala> import scalaz.contrib.std.scalaFuture._ // typeclass instances for Scala Future | |
import scalaz.contrib.std.scalaFuture._ | |
scala> import ExecutionContext.Implicits.global // implicit execution context...you probably want a better one for real-world | |
import ExecutionContext.Implicits.global | |
scala> type ErrorsOrT[M[+_], +A] = EitherT[M, NonEmptyList[String], A] // String could be your error type of choice | |
defined type alias ErrorsOrT | |
scala> :paste | |
// Entering paste mode (ctrl-D to finish) | |
for { | |
thing1 <- EitherT(Future.successful(1.right)) | |
thing2 <- Future.successful(2).liftM[ErrorsOrT] | |
} yield thing1 + thing2 | |
// Exiting paste mode, now interpreting. | |
res7: scalaz.EitherT[scala.concurrent.Future,scalaz.NonEmptyList[String],Int] = scalaz.EitherTFunctions$$anon$11@45d1a86c |
Lifting to Future[Error \/ A]
to EitherT[Future, Error, A]
can be accomplished with EitherT.eitherT()
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can
Future[Error \/ A]
be lifted toEitherT[Future, Error, A]
in a same way?