Created
November 25, 2010 11:47
-
-
Save remeniuk/715260 to your computer and use it in GitHub Desktop.
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
//////////////// Scalaz Validation | |
sealed trait Name extends NewType[String] | |
object Name { | |
def apply(s: String): Validation[String, Name] = if (s.headOption.exists(_.isUpper)) | |
(new Name {val value = s}).success | |
else | |
"Name must start with a capital letter".fail | |
} | |
sealed trait Age extends NewType[Int] | |
object Age { | |
def apply(a: Int): Validation[String, Age] = if (0 to 130 contains a) | |
(new Age {val value = a}).success | |
else | |
"Age must be in range".fail | |
} | |
case class Person(name: Name, age: Age) | |
//////////////// JEE 6 Bean Validation | |
case class Person(@NotNull @Pattern(regexp="[A-Z]\\w+") name: String, @Min(0) @Max(130) age: Int) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment