Hi! I'm currently working on an Arrow integration for
#akkurate, my validation library. Currently, to run the validation, you write
validate(someDataClass)
, which
returns a ValidationResult.
I want my users to be able to smoothly incorporate the validation result with Arrow's typed results. Here are the current ideas I had.
toEither()
val result = validate(someDataClass)
val either: Either<ConstraintViolation, SomeDataClass> = result.toEither()
val eitherMessage = either.fold(
ifLeft = { "Failure: $it" },
ifRight = { "Success: $it" },
)
In case of failure,
it
is the first
ConstraintViolation encountered
In case of success,
it
is the value being validated
toEitherNonEmptySet()
val result = validate(someDataClass)
val either: Either<NonEmptySet<ConstraintViolation>, SomeDataClass> = result.toEitherNonEmptySet()
val eitherMessage = either.fold(
ifLeft = { "Failure: $it" },
ifRight = { "Success: $it" },
)
In case of failure,
it
is a
NonEmptySet<ConstraintViolation>
In case of success,
it
is the value being validated
bind()
val either: Either<NonEmptySet<ConstraintViolation>, SomeDataClass> = either {
val result = validate(someDataClass)
bind(result)
}
val eitherMessage = either.fold(
ifLeft = { "Failure: $it" },
ifRight = { "Success: $it" },
)
In case of failure,
it
is a
NonEmptySet<ConstraintViolation>
In case of success,
it
is the value being validated
I'm not a frequent user of Arrow, I would really appreciate what you think about this API.
One thing that already bothers me, is how
toEither
defaults to a single violation constraint (unless explicitely using
toEitherNonEmptySet
), meanwhile
bind
raises multiple violation constraints. What do you think about this?