Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- object Heltal {
- def unapply(x: String): Option[Int] = try {
- Some(x.toInt)
- } catch {
- case e: NumberFormatException => None
- }
- }
- def runMatch(s: String) = s match {
- case Heltal(x) => println(x + 1)
- case _ => println("NaN")
- }
- @ runMatch("hi")
- NaN
- @ runMatch("10")
- 11
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement