Skip to content

Instantly share code, notes, and snippets.

@tinoadams
Created May 27, 2012 23:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tinoadams/2816402 to your computer and use it in GitHub Desktop.
Save tinoadams/2816402 to your computer and use it in GitHub Desktop.
Value object sample with parsing and validation
package samples
case class AustralianPostcode private (value: String) {
require(value.matches("""\d{4}"""))
}
object AustralianPostcode {
def parse(value: String) = new AustralianPostcode(value.trim)
}
object Main extends App {
val p = AustralianPostcode parse " 1234"
println(p)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment