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