First of all, let’s define the signature
def applyF1ToBoth(lat: Int, long: Int): Either[E, (Double, Double)]
As we can see from the signature, we want to either fail with an E
, or succeed with a pair of doubles.
Then, we apply the function to both lat
and long
and place the results into a tuple, but not as Either
, let’s transform them into ValidatedNonEmptyChain
.
🤔 Why a ValidatedNonEmptyChain[E, Double]
instead of a “simple” Validated[E, Double]
(like the “original” return type, which is Either[E, Double]
)?
That is because we want to be able to combine a non-empty collection of errors (in our case it might be an error or no error at all, but the Chain
data structure helps us to combine multiple errors).