Guest User

Untitled

a guest
Oct 16th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.33 KB | None | 0 0
  1. scala> import scala.util.control.Exception.allCatch
  2. import scala.util.control.Exception.allCatch
  3.  
  4. scala> def intValueOf(s: String): Option[Int] = allCatch.opt { s.toInt }
  5. intValueOf: (s: String)Option[Int]
  6.  
  7. scala> val x = intValueOf("hello")
  8. x: Option[Int] = None
  9.  
  10. scala> val y = intValueOf("12345")
  11. y: Option[Int] = Some(12345)
Add Comment
Please, Sign In to add comment