Asking here, in case someone knows. I have a list ...
# arrow
c
Asking here, in case someone knows. I have a list of
Either<A, X>
where
A
are typed errors and
X
varies. I want to accumulate the errors and zip up the `X`'s. I can use
zipOrAccumulate
for validations, but I don't need to validate the Either s, they are already validated.
a
you can do
Copy code
zipOrAccumulate(
  { firstThing.bind() },
  { secondThing.bind() },
  ...,
  ::Pair // or ::Triple, ::Tuple4, ...
}
p
Do you mean something like:
Copy code
inline fun <A, X, R> Iterable<Either<A, X>>.foldOrAccumulate(initial: R, operation: (acc: R, X) -> R): EitherNel<A, R> =
    either { flattenOrAccumulate().bind().fold(initial, operation) }
or just
Copy code
Iterable<Either<Error, A>>.flattenOrAccumulate(): Either<NonEmptyList<Error>, List<A>>
a more optimized
foldOrAccumulate
could probably be implemented that avoids mapping to an intermediate list
c
Thanks guys. I'll look into these.