Skip to content

Instantly share code, notes, and snippets.

@frgomes
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frgomes/09a63a6c99ba0eb8a59d to your computer and use it in GitHub Desktop.
Save frgomes/09a63a6c99ba0eb8a59d to your computer and use it in GitHub Desktop.
Scala - Reporting validations
def transmit[R: ClassTag](message: R, validations: (R => Seq[Option[Throwable]])*) = {
val conditions: Seq[Option[Throwable]] =
(Seq.empty[Option[Throwable]] /: (for { validation <- validations } yield { validation(message)} )) {
case (acc, item) => acc ++ item }
val lines =
(0 /: conditions.flatten) {
case (n, e) =>
val line = n + 1
log.error(s"VALIDATION #${line} :: " + e.getMessage + s"\n" + e.getStackTraceString)
line }
if(lines > 0) Assertions.fail(s"${lines} error(s) detected. See log messages above.")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment