How to combine two Validation<Error, Unit>? #1292
-
I am not sure if I am heading the right direction. If both are Success, then combining the two would return Success. Otherwise return Fail with all Errors from both. How do I do this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Use the 'coalescing' operator: Validation<Error, Unit> mx = ...;
Validation<Error, Unit> my = ...;
var mr = mx | my; I kinda wish I'd used the You can also use var mr = (mx, my).Apply((x, y) => unit); Finally, if you only care about getting the first error and not all errors: var mr = from x in mx
from y in my
select unit; Definitely finally, there's a nice |
Beta Was this translation helpful? Give feedback.
Use the 'coalescing' operator:
I kinda wish I'd used the
&
operator, but there it is.You can also use
Apply
(which is the applicative-functor operator), it allows you to get at the values of the validation if they all succeed, and returns all the errors if any fail.Finally, if you only care about getting the first error and not all errors:
Definitely finally, there's a nice
ValidateCreditCard
example in the unit-tests that visits all the different approaches to using the…