Sorry for disturbing the discussion but I have que...
# arrow
s
Sorry for disturbing the discussion but I have question regarding the use of a group of Eithers. Is List<Either<a,b>> an anti-pattern? If not, how do you handle the left cases in a good way? Let's say that if one of the Eithers is left I want to stop and bubble the Left?
p
list.sequence(Either.applicative())
may be what you're after
oh, it actually doesn't short on errors, it just aggregates them together 😄
so yeah,
sequence
is what you want
it'll stop on the first Either error tho
if what you want is aggregate errors, map to ValidatedNel first
Validated never shorts, and it aggregates errors in the NonEmptyList (nel) on the left side
s
list.asSequence(Either.applicative<T>())
?
p
no
sequence, the extension function. It should be declared for List, otherwise
list.k().sequence(...)
s
Sorry for asking dumb questions but is this the right sequence? https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.sequences/-sequence/index.html
b
No, it should be the
sequence
defined on
ListK
in Arrow
p
No such thing as dumb questions Stian. You have to make sure to have the right import, in this case the extension function
sequence
defined in the interface
Traverse
import arrow.core.extensions.list.traverse.*
s
Thank you 🙂