Skip to content

Instantly share code, notes, and snippets.

@mpilquist
Forked from anonymous/gist:4370153
Created December 24, 2012 18:37
Show Gist options
  • Save mpilquist/4370310 to your computer and use it in GitHub Desktop.
Save mpilquist/4370310 to your computer and use it in GitHub Desktop.
class Age private (val v: Short) extends AnyVal {
def isInfant = v < 2
def isToddler = v >= 2 && v <= 4
def isSenior = v >= 50
}
object Age {
def apply(v: Short): Age = {
require(v >= 0 && v < 200, "Must be between 0 and 200")
new Age(v)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment