I go up to competence on Cats Validated and I have a problem to concatenate my error accumulator.
I get this error
Error:(88, 17) discarded non-Unit value
errorList ++= errors
I don't know how can I resolve this error.
My code :
def checkValidity(types: List[Type]): ValidationResult[Boolean] = {
val errorList: mutable.MutableList[String] = mutable.MutableList.empty
schemas.foreach { schema =>
for (errors <- schema.checkValidity(types).invalid[List[String]]) {
errorList ++= errors
}
}
}
Thanks for your help.
Full code
I have two case class in two different file:
case class Domain(
name: String,
directory: String,
metadata: Option[Metadata] = None,
schemas: List[Schema] = Nil,
comment: Option[String] = None,
extensions: Option[List[String]] = None,
ack: Option[String] = None
) {
case class Schema(
name: String,
pattern: Pattern,
attributes: List[Attribute],
metadata: Option[Metadata],
merge: Option[MergeOptions],
comment: Option[String],
presql: Option[List[String]],
postsql: Option[List[String]]
)
I want to check all errors and add errors in my accumulator list. At the final, if this list is empty I return Valid(true) else I return Invalid(myAccumulatorList)
The complete code of the function in Domain.scala file:
def checkValidity(types: List[Type]): ValidationResult[Boolean] = {
val errorList: mutable.MutableList[String] = mutable.MutableList.empty
// Check Domain name validity
val dbNamePattern = Pattern.compile("[a-zA-Z][a-zA-Z0-9_]{1,100}")
if (!dbNamePattern.matcher(name).matches())
errorList += s"Schema with name $name should respect the pattern ${dbNamePattern.pattern()}"
// Check Schema validity
schemas.foreach { schema =>
for (errors <- schema.checkValidity(types).invalid[List[String]]) {
errorList ++= errors
}
}
val duplicatesErrorMessage = "%s is defined %d times. A schema can only be defined once."
for (errors <- duplicates(schemas.map(_.name), duplicatesErrorMessage).invalid[List[String]]) {
errorList ++= errors
}
// TODO Check partition columns
// TODO Validate directory
val inputDir = File(this.directory)
if (!inputDir.exists) {
errorList += s"$directory not found"
}
if (errorList.nonEmpty)
Invalid(errorList.toList)
else
Valid(true)
}