wix-incubator / accord

Accord: A sane validation library for Scala
http://wix.github.io/accord/
Other
529 stars 55 forks source link

How to Handle Option #54

Closed lenzenc closed 9 years ago

lenzenc commented 9 years ago

I'm trying to figure out what is the best practice for handling Option, for example;

 case class Person(name: String, age: Option[Int] = None)

implicit val personValidator = validator[Person] { p =>
    p.name is notEmpty
    p.age is between(21, 40)
}

In this case I only want to validate "age" if it is Some.

Thoughts?

holograph commented 9 years ago

You can use .each for that (i.e. p.age.each is between(...)). It should be covered in the documentation on the project site, though - is it not clear enough?

lenzenc commented 9 years ago

Thanks, will give that a try. As far as I can see I don't see any documentation about using "each"; http://wix.github.io/accord/

holograph commented 9 years ago

It's at http://wix.github.io/accord/dsl.html. The site could really use a TOC, and I could really use some help from anyone conversant in CSS to get it done properly :-)