Skip to content

Instantly share code, notes, and snippets.

@kelsey-sorrels
Created June 18, 2016 03:00
Show Gist options
  • Save kelsey-sorrels/0f8b3fc7f5847157a42926f3bb59ccf7 to your computer and use it in GitHub Desktop.
Save kelsey-sorrels/0f8b3fc7f5847157a42926f3bb59ccf7 to your computer and use it in GitHub Desktop.
For/yield followed by match
import scala.util.{Try, Success, Failure}
// Where this syntax scans
(for {
x <- Try("3".toInt)
y <- Try("4".toInt)
} yield {
x + y
}) match {
case Success(n) => println(n)
case Failure(t) => println(t.getMessage)
}
// But does not
for {
x <- Try("3".toInt)
y <- Try("4".toInt)
} yield {
x + y
} match {
case Success(n) => println(n)
case Failure(t) => println(t.getMessage)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment