Effect CommunityEC
Effect Community3y ago
11 replies
Jérôme MARTIN

Same as Either.all but returning all errors

I have a bunch of Either's E.Either<E1,A1>,...E.Either<EN,An>. I am looking for a function that would returna left with all the errors: E.left<[E1,...,En] if there is at least one left . Otherwise it returns a right with all the results: E.right<[A1,...,An]>. The goal is to run all effects, return all the errors if there are some or return all the results if there are none. Very similar to E.all except that all stops at the first left.

So far, I handled this situation with ReadOnlyArray.partitionMap. After partitioning my eithers in lefts and rights, I check if the length of the group of lefts is at least one,... But it's a bit tedious. I have come across this situation several times. So I wonder if I haven't missed something.
Was this page helpful?