Asking here, in case someone knows. I have a list ...
# arrow
c
Asking here, in case someone knows. I have a list of
EitherA, 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<EitherA, X>.foldOrAccumulate(initial: R, operation: (acc: R, X) -> R): EitherNelA, R =
    either { flattenOrAccumulate().bind().fold(initial, operation) }
or just
Copy code
Iterable<EitherError, A>.flattenOrAccumulate(): Either<NonEmptyListError, ListA>
a more optimized
foldOrAccumulate
could probably be implemented that avoids mapping to an intermediate list
c
Thanks guys. I'll look into these.