Johann Pardanaud
12/06/2023, 11:31 AMvalidate(someDataClass)val result = validate(someDataClass)
val either: Either<ConstraintViolation, SomeDataClass> = result.toEither()
val eitherMessage = either.fold(
    ifLeft = { "Failure: $it" },
    ifRight = { "Success: $it" },
)ititval result = validate(someDataClass)
val either: Either<NonEmptySet<ConstraintViolation>, SomeDataClass> = result.toEitherNonEmptySet()
val eitherMessage = either.fold(
    ifLeft = { "Failure: $it" },
    ifRight = { "Success: $it" },
)itNonEmptySet<ConstraintViolation>itval either: Either<NonEmptySet<ConstraintViolation>, SomeDataClass> = either {
    val result = validate(someDataClass)
    bind(result)
}
val eitherMessage = either.fold(
    ifLeft = { "Failure: $it" },
    ifRight = { "Success: $it" },
)itNonEmptySet<ConstraintViolation>ittoEithertoEitherNonEmptySetbindstojan
12/06/2023, 11:40 AMValidationResultSetfun <A> ValidationResult.toEither(): Either<NonEmptySet<ConstraintViolation>, A> = TODO()EithereitherValidationResultAlejandro Serrano.Mena
12/06/2023, 11:52 AMtoEither()NonEmptyList<ConstraintViolation>Johann Pardanaud
12/06/2023, 11:52 AMJohann Pardanaud
12/06/2023, 11:52 AMNext level would be to create your own DSL forI already read the guide about creating your own DSL, but I'm not sure I see the point?e.g. https://arrow-kt.io/learn/typed-errors/own-error-types/ValidationResult
Alejandro Serrano.Mena
12/06/2023, 11:52 AMtoEitherbindJohann Pardanaud
12/06/2023, 11:53 AMAlejandro Serrano.Mena
12/06/2023, 11:54 AMJohann Pardanaud
12/06/2023, 11:55 AMAlejandro Serrano.Mena
12/06/2023, 11:59 AMeither {
  ... do something ...
  val validatedTitle = akkurate(title) {
    it.isNotEmpty() otherwise { "Missing title" }
  }
}fun <A> Raise<...> akkurate(subject: A, validator: Validatable<ValueType>.() -> Unit): A = 
  Validator<A>(validator)(subject).bind()Johann Pardanaud
12/06/2023, 12:11 PMAlejandro Serrano.Mena
12/06/2023, 12:43 PMJohann Pardanaud
12/06/2023, 12:58 PMAlejandro Serrano.Mena
12/06/2023, 1:31 PMJohann Pardanaud
12/06/2023, 1:33 PM