Created
June 18, 2016 03:00
-
-
Save kelsey-sorrels/0f8b3fc7f5847157a42926f3bb59ccf7 to your computer and use it in GitHub Desktop.
For/yield followed by match
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
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