fork 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: Int) => numberOrDefault(x)) compose divideByZero _ })
  9. println(Success(1) map divideByZero _ map ((x: Int) => numberOrDefault(x)))
  10. }
Success #stdin #stdout 0.39s 382016KB
stdin
Standard input is empty
stdout
Failure(java.lang.ArithmeticException: / by zero)
Failure(java.lang.ArithmeticException: / by zero)