Skip to content

Instantly share code, notes, and snippets.

@dipakc
dipakc / RefactoringTryCatchFor.scala
Created November 9, 2012 05:39
Refactoring: try catch inside for comprehension
import scala.util.control.Exception._
object RefactoringTryCatchFor {
/////////////////////////////////////////
for {
x <- List(10, 20, 30)
y <- List(0, 1, 2)
val zOpt = try { Some(x / y) } catch { case _ => None }
if (zOpt.isDefined)
} yield {