Last active
August 29, 2015 14:10
-
-
Save milessabin/eeb3fd6fc669e1e42fc9 to your computer and use it in GitHub Desktop.
Simple EitherT demo
This file contains hidden or 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 demo | |
import scalaz._ | |
import scalaz.syntax._ | |
import scalaz.effect.IO | |
import scalaz.effect.IO._ | |
import scalaz.syntax.std.either._ | |
object Demo { | |
type M[A] = EitherT[IO, Throwable, A] | |
def op1: M[String] = EitherT(IO(\/-("foo"))) | |
//def op2(s: String): M[Int] = EitherT(IO(\/-(s.length))) | |
def op2(s: String): M[Int] = EitherT(IO(-\/(new Throwable))) | |
def op3(i: Int): M[Unit] = EitherT(IO(\/-(println(i)))) | |
def main(args: Array[String]): Unit = { | |
val effect: M[Unit] = | |
for { | |
res1 <- op1 | |
res2 <- op2(res1) | |
res3 <- op3(res2) | |
} yield res3 | |
val res: Throwable \/ Unit = | |
effect.run.unsafePerformIO | |
println(s"res: $res") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment