Validation in Scala with Cats effect and ZIO
Briefly

Validation 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"
"One thing I quickly came to appreciate about ZIO (and effect system in general) is that function signatures do not lie. Along with the happy path of what it returns it tells you what error to expect. In case of ZIO it also tells you the environment (resources) the function depends on. For example, in Cats Effect you will see IO[Error, A] while in ZIO the type is ZIO[Resource, Error, A]"
ValidatedNel aggregates multiple validation failures into a NonEmptyList instead of short-circuiting on the first error. mapN can convert validated tuples into a case class for clearer results. Example usage shows Invalid(NonEmptyList(...)) producing all error messages together, e.g., missing name and invalid phone length. The ValidatedNel type is an alias: Validated[NonEmptyList[E], A]. EitherNel exists for compatibility but behaves like a regular Either and does not accumulate errors. ZIO encodes required environment and error types in function signatures and suspends side effects to maintain referential transparency.
Read at Medium
Unable to calculate read time
[
|
]