Chuong
09/13/2024, 8:56 AMEither<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.Alejandro Serrano.Mena
09/13/2024, 9:09 AMzipOrAccumulate(
{ firstThing.bind() },
{ secondThing.bind() },
...,
::Pair // or ::Triple, ::Tuple4, ...
}
phldavies
09/13/2024, 10:29 AMinline 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
Iterable<Either<Error, A>>.flattenOrAccumulate(): Either<NonEmptyList<Error>, List<A>>
phldavies
09/13/2024, 10:32 AMfoldOrAccumulate
could probably be implemented that avoids mapping to an intermediate listChuong
09/13/2024, 2:21 PM