Skip to content

Instantly share code, notes, and snippets.

@holograph
Last active December 31, 2015 00:59
Show Gist options
  • Save holograph/7910661 to your computer and use it in GitHub Desktop.
Save holograph/7910661 to your computer and use it in GitHub Desktop.
A sample validator definition for Accord (https://github.com/wix/accord).
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