Last active
April 24, 2016 21:27
-
-
Save etorreborre/3f6f63bd9f6964c8fc722c3fc7211ed3 to your computer and use it in GitHub Desktop.
Experiment using the Eff monad to test deeply nested structures
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
val e = Option(List(Right(2), Left("bad"))) | |
runResult { | |
for { | |
as <- (e must beSome).opt | |
a <- fromList(as) | |
i <- (a must beRight).opt | |
_ <- (i must be_>(0)).check | |
} yield () | |
} | |
// without eff | |
e must beSome { ss: List[Either[String, Int]] => | |
ss must contain { s: Either[String, Int] => | |
s must beRight { i: Int => | |
i must be_>(0) | |
} | |
}.forall | |
} | |
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
// with eff this prints | |
[error] Context | |
[error] Some(List(Right(2), Left(bad))): OK | |
[error] Right(2): OK | |
[error] 2: OK | |
[error] 'Left(bad)' is not Right (MatchEffects.scala:29) | |
// without eff this prints | |
[error] 'Some(List(Right(2), Left(bad)))' is Some but There is 1 failure | |
[error] 'Left(bad)' is not Right (MatchEffects.scala:38) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment