I'm a beginner with Cats. I have an error with Validated cats. I use a list accumulator like that :
case class Type(
name: String,
pattern: String,
primitiveType: PrimitiveType = PrimitiveType.string,
sample: Option[String] = None,
comment: Option[String] = None,
stat: Option[Stat] = None
) {
type ValidationResult[A] = Validated[List[String], A]
def checkValidity(): ValidationResult[Boolean] = {
val errorList: mutable.MutableList[String] = mutable.MutableList.empty
val patternIsValid = Try {
primitiveType match {
case PrimitiveType.struct =>
case PrimitiveType.date =>
new SimpleDateFormat(pattern)
case PrimitiveType.timestamp =>
pattern match {
case "epoch_second" | "epoch_milli" =>
case _ if PrimitiveType.formatters.keys.toList.contains(pattern) =>
case _ =>
DateTimeFormatter.ofPattern(pattern)
}
case _ =>
Pattern.compile(pattern)
}
}
if (patternIsValid.isFailure)
errorList += s"Invalid Pattern $pattern in type $name"
val ok = sample.forall(this.matches)
if (!ok)
errorList += s"Sample $sample does not match pattern $pattern in type $name"
if (errorList.nonEmpty)
Invalid(errorList.toList)
else
Valid(true)
}
}
When I use this function with my case class Types :
case class Types(types: List[Type]) {
type ValidationResult[A] = Validated[List[String], A]
def checkValidity(): ValidationResult[Boolean] = {
val typeNames = types.map(_.name)
val dup: ValidationResult[Boolean] =
duplicates(typeNames, s"%s is defined %d times. A type can only be defined once.")
(dup,types.map(_.checkValidity()).sequence).mapN((_,_) => true)
}
}
I have this error
Error:(29, 39) Cannot prove that cats.data.Validated[List[String],Boolean] <:< G[A].
(dup,types.map(_.checkValidity()).sequence: _*).mapN((_,_) => true)
Can you help me to resolve this error?
Thanks for your help.