Skip to content

Instantly share code, notes, and snippets.

@danclien
Created August 10, 2013 21:45
Show Gist options
  • Save danclien/6202300 to your computer and use it in GitHub Desktop.
Save danclien/6202300 to your computer and use it in GitHub Desktop.
def wrap(in: Option[String]) : Option[String] = {
println("Running")
in
}
//Setup Option[String]s
lazy val maybeValue1 : Option[String] = wrap(Some("Value1"))
lazy val maybeValue2 : Option[String] = wrap(None)
lazy val maybeValue3 : Option[String] = wrap(Some("Value3"))
// Checking each value using a for comprehension
(for { _ <- maybeValue1; _ <- maybeValue2; _ <- maybeValue3 } yield ()) match {
case None => println("Handle error here")
case _ => println("Do stuff here")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment