Created
May 27, 2012 23:38
-
-
Save tinoadams/2816402 to your computer and use it in GitHub Desktop.
Value object sample with parsing and validation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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