Skip to content

Instantly share code, notes, and snippets.

@kevinmeredith
Created July 9, 2016 17:32
Show Gist options
  • Select an option

  • Save kevinmeredith/4297cdf70193ce938c5b4ef683cdfe75 to your computer and use it in GitHub Desktop.

Select an option

Save kevinmeredith/4297cdf70193ce938c5b4ef683cdfe75 to your computer and use it in GitHub Desktop.
DB Constraints to support smart constructor?

Smart Constructor

class Person private(name: String, age: Int)

object Person {
  def apply(name: String, age: Int): Option[Person] = 
    if (name.nonEmpty && age >= 0 && age < 115) Some( new Person(name, age) ) else None
}

PERSON table

ID | NAME | AGE
---------------
1    foo    -42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment