Last active
December 31, 2015 00:59
-
-
Save holograph/7910661 to your computer and use it in GitHub Desktop.
A sample validator definition for Accord (https://github.com/wix/accord).
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
import com.wix.accord.dsl._ // Import the validator DSL | |
case class Person( firstName: String, lastName: String ) | |
case class Classroom( teacher: Person, students: Seq[ Person ] ) | |
implicit val personValidator = validator[ Person ] { p => | |
p.firstName is notEmpty // The expression being validated is resolved automatically, see below | |
p.lastName as "last name" is notEmpty // You can also explicitly describe the expression being validated | |
} | |
implicit val classValidator = validator[ Classroom ] { c => | |
c.teacher is valid // Implicitly relies on personValidator! | |
c.students.each is valid | |
c.students have size > 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment