Skip to content

Instantly share code, notes, and snippets.

@dirkgr
Created November 20, 2014 23:56
Show Gist options
  • Save dirkgr/96d1f06ef097dc36aa5e to your computer and use it in GitHub Desktop.
Save dirkgr/96d1f06ef097dc36aa5e to your computer and use it in GitHub Desktop.
Pattern matching on Int
// pattern matching on Int
object Int {
def unapply(s: String): Option[Int] = try {
Some(s.toInt)
} catch {
case _: java.lang.NumberFormatException => None
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment