Skip to content

Instantly share code, notes, and snippets.

@etorreborre
Last active April 24, 2016 21:27
Show Gist options
  • Save etorreborre/3f6f63bd9f6964c8fc722c3fc7211ed3 to your computer and use it in GitHub Desktop.
Save etorreborre/3f6f63bd9f6964c8fc722c3fc7211ed3 to your computer and use it in GitHub Desktop.
Experiment using the Eff monad to test deeply nested structures
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
}
// 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