Hello, I saw yesterday's annoucement of akkurate a...
# akkurate
r
Hello, I saw yesterday's annoucement of akkurate and took a quick glance at it. I was wondering why you've chosen to implement your own
ValidationResult
class instead of e.g. using Arrow's
Either
. I guess the latter would make for a better interoperability.
p
You can create extension functions for the mapping from
ValidationResult
to `Either`/`EitherNel` . Something like below:
Copy code
fun <T> ValidationResult<T>.toEitherNel(): EitherNel<Failure, T> =
    when (this) {
        is ValidationResult.Success<T> -> Either.Right(this.value)
        is ValidationResult.Failure -> {
            Either.Left(this.violations.map { Failure.ValidationFailure(it.message) }.toNonEmptyList())
        }
    }

fun <T> ValidationResult<T>.toEither(): Either<Failure, T> =
    when (this) {
        is ValidationResult.Success<T> -> Either.Right(this.value)
        is ValidationResult.Failure -> {
            Either.Left(Failure.ValidationFailure(this.violations.joinToString { it.message }))
        }
    }
r
I was wondering about the design decision
p
Isn't that forcing the user to have a dependency to Arrow Core?
r
Well, yes, but then you'd have a well tested implementation instead of the n-th own implementation of an Either
p
That's correct.
j
The extra dependency is the reason, not everyone is using Arrow 😉 But I will provide soon an integration to cast the result to an Either, like the extension function @PoisonedYouth wrote.
👍 2