Created
October 15, 2014 16:46
-
-
Save noelmarkham/80ba52ca9de54f11894a to your computer and use it in GitHub Desktop.
These
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
import scalaz._ | |
import Scalaz._ | |
import \&/._ | |
sealed trait Error | |
case class NotFatalError(reason: String) extends Error | |
case class FatalError(reason: String) extends Error | |
def function(i: Int): List[Error] \&/ Int = i match { | |
case 0 => This(List(NotFatalError("Zero returned"))) | |
case 1 => This(List(FatalError("One is fatal"))) | |
case 2 => Both(List(NotFatalError("Both?")), 2) | |
case x => That(x) | |
} | |
val first = for { | |
a <- function(10) | |
b <- function(11) | |
} yield a + b | |
val second = for { | |
a <- function(10) | |
b <- function(1) | |
} yield a + b | |
val third = for { | |
a <- function(1) | |
b <- function(1) | |
c <- function(1) | |
d <- function(2) | |
} yield a + b | |
val fourth = for { | |
a <- function(2) | |
b <- function(2) | |
} yield a + b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment