Hey new to the channel and arrow. Let's say that I...
# arrow
d
Hey new to the channel and arrow. Let's say that I have ValidatedNel<Error, ValidatedNel<Error, T>>. How can I convert that to ValidatedNel<Error, T>?
👋 1
p
oooooh, we went through this in another channel a couple of days ago
let’s see if I can explain myself better now 😄
😄 1
Validated doesn’t form a monad, so it doesn’t have flatMap or flatten to do the operation automatically
the best you can do is
fold
myNested.fold({ it.invalidNel() }, ::identity)
the errors propagate if there are any, otherwise apply the new nested operation
you can never get errors from both the top-level and the nested operation together, because one precedes the other
if they don’t, use
ValidatedNel.applicative().mapN(valNel1, valNel2) { /* non-validated */ }
d
Thanks you! That worked. I just had to make one small change which was:
Copy code
myNested.fold({it.invalid()}, ::identity)
p
😄