fork(1) download
  1. import scala.util._
  2.  
  3. object Main extends App {
  4. def divideByZero(a: Int): Int = a / 0
  5. def numberOrDefault(a: => Int): Int =
  6. try a catch { case _: ArithmeticException => 42 }
  7.  
  8. println(Success(1) map { x => numberOrDefault(divideByZero(x)) })
  9. println(Success(1) map divideByZero _ map ((x: Int) => numberOrDefault(x)))
  10. }
Success #stdin #stdout 0.37s 382080KB
stdin
Standard input is empty
stdout
Success(42)
Failure(java.lang.ArithmeticException: / by zero)