Hello, Is there a function to combine two validate...
# arrow
l
Hello, Is there a function to combine two validated variable to check is they are compatible with each other Maybe a function like this to allow some check with both values
Copy code
Validated<ValidationError, Enum1>, Validated<ValidationError, Enum2> -> Validated<Nel<ValidationError>, Pair<Enum1, Enum2>>
l
I tried with zip but the result type is
Copy code
Validated<Nel<ValidationError>, Validated<Nel<ValidationError>, Pair<Enum1, Enum2>>>
maybe I did something wrong with the type, I will check
s
``fun <E, A, B, Z> ValidatedNel<E, A>.zip(b: ValidatedNel<E, B>, f: (A, B) -> Z): ValidatedNel<E, Z>`` this signature should work for you 👆 right?
or maybe you need to transform your error to
ValidatedNel
first
l
My problem is that errors inside the zip function are not combined with the error outside
s
I think you want
a.toValidatedNel().zip(b.toValidatedNel(), ::Pair)
l
Not really because I need to validate the combination of a and b inside the function. that why I get two validation errors in my return type when I use zip
s
Can you share a full snippet with type signatures
I’m not sure what you mean, my implementation matches the desired signature you shared
l
I made a new project to show what I mean https://github.com/lidonis/arrow-playground/blob/master/src/main/kotlin/ValidatedCombination.kt The method checkCombination doesn't compile because it doesn't match the signature I wanted
s
210 Views