Skip to content

Instantly share code, notes, and snippets.

@petekneller
Forked from milessabin/gist:eeb3fd6fc669e1e42fc9
Last active September 14, 2015 10:03
Show Gist options
  • Save petekneller/128372a634450f0a6a19 to your computer and use it in GitHub Desktop.
Save petekneller/128372a634450f0a6a19 to your computer and use it in GitHub Desktop.
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