Replies: 2 comments
-
This PR #2872 proposes yet another way to introduce an accumulating function, in this case generic over every |
Beta Was this translation helpful? Give feedback.
0 replies
-
Here is a use-case for the 2nd signature, https://github.com/arrow-kt/arrow/pull/2863/files#diff-74bf2a702683ff9b5377a1d02d00a2708862d90d5d5dc25e72f675283ee14b1cR73. Name is up for debate, but it's needed to derive the parallel version After some discussion in the last bi-weekly Arrow meeting, I am in favour of adding both options |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
During the discussion in #2795, the issue of a good function that works over
Iterable<Either<E, A>
was raised by @pakoito. Here are some of the ideas gathered, so we can discuss them separately from that PR.1.
Iterable<Either<E, A>>.sequence(): Either<E, List<A>>
This function is very similar to the
sequence
found in other languages; it returns the original list of elements, or bails out if any of them isLeft
. Note that this only returns the first error.2.
Iterable<Either<E, A>>.flattenOrAccumulate(): Either<NonEmpty<E>, List<A>>
This was suggested by @nomisRev in an internal conversation. The idea is that it works like
sequence
above, but doesn't stop at the first error. This suits a bit better with the new API in which we try to maintain errors as far as possible, as we used to do withValidated
.3.
suspend Iterable<Either<E, A>>.bindAll(): List<A>
This would be just a shortcut to
map { it.bind() }
. The idea is to stay within the DSL, but has the disadvantage that you need to writeeither { list.bindAll() }
to recover the behavior ofsequence
; it also stops on the first error.Beta Was this translation helpful? Give feedback.
All reactions