Skip to content

Instantly share code, notes, and snippets.

@dchenbecker
Created May 6, 2010 13:22
Show Gist options
  • Save dchenbecker/392119 to your computer and use it in GitHub Desktop.
Save dchenbecker/392119 to your computer and use it in GitHub Desktop.
scala> object PositiveInt {
| def unapply (input : String) = try { if (input.toInt > 0) Some(input.toInt) else None } catch { case _ ⇒ None }
| }
defined module PositiveInt
scala> List("foo","bar","14") match {
| case group :: user :: PositiveInt(id) :: Nil ⇒ println("%s:%s (%d)".format(group, user, id))
| case _ ⇒ // NOP
| }
foo:bar (14)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment