What is the correct way to transform an `Iterable&...
# arrow
c
What is the correct way to transform an
Iterable<Either<L,R>>
into a
Validated<Nel<L>, R>
? For more context, I’m using parTraverse on a collection, returning an
Either<L,R>
for each item. I’d like to collect that into a
Validated<Nel<L>,R
to that I can take the left path if there are any errors and collect that into some useful log message. It looks something like
Copy code
items
  .parTraverse { doWork(it, foo) }
  .toValidated() // This is what I'm trying to figure out.
  .mapLeft { makeErrorMessage(it) // where it is Nel<L> }

fun doWork() : Either<L,R>
1
s
A short rewrite of your snippet with
parTraverseValidated
.
Copy code
items  .parTraverseValidated(Semigroup.nonEmptyList()) {
  doWork(it, foo).toValidatedNel()
}
c
This is exactly what I was looking for, thank you 🙂
👍 1