Last active
August 29, 2015 14:27
-
-
Save frgomes/09a63a6c99ba0eb8a59d to your computer and use it in GitHub Desktop.
Scala - Reporting validations
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 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