fork download
  1. object Main extends App {
  2. val resultOption: Option[Int] =
  3. for{
  4. i1 <- opt1
  5. i2 <- opt2
  6. } yield {
  7. if(i1 + i2 > 10) null.asInstanceOf[Int]
  8. else i1 + i2
  9. }
  10.  
  11. println(resultOption)
  12.  
  13. def opt1: Option[Int] = Some(5)
  14. def opt2: Option[Int] = Some(10)
  15. }
Success #stdin #stdout 0.48s 66168KB
stdin
Standard input is empty
stdout
Some(0)