fromMedium
1 week agoValidation in Scala with Cats effect and ZIO
The main idea is that instead of short circuiting on the first error, ValidatedNel accumulates all error in an NonEmptyList. If you prefer using a case class rather than tuple you can use mapN instead. Running this we can see that we get all the error messages. def validateInput (maybeName: Option[String], phone: String): cats.data.ValidatedNel[String, ResultTuple]val result: cats.data.ValidatedNel[String, ResultTuple] = Invalid(NonEmptyList(Name cannot be empty, Phone number must be 8 digits))Invalid input: Name cannot be empty, Phone number must be 8 digits
Software development