-
-
Save seanparsons/2844124 to your computer and use it in GitHub Desktop.
validateanyProduct.scala
This file contains 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
def validateProduct[T <: Product](product: T): Seq[String] = product.productIterator.flatMap{value => value match { | |
case null => Seq("null attributes are not allowed for " + product) | |
case string: String if (string.isEmpty) => Seq("Empty strings are not allowed for " + product) | |
case innerProduct: Product => validateProduct(innerProduct) | |
case _ => Seq() | |
}}.toSeq |
Yeah, that's much nicer.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Slightly cleaner, perhaps.