Sagar Suri
07/21/2020, 1:31 PMJannis
07/21/2020, 1:38 PMsequence
from the Traverse
typeclass. We have quite good docs for this typeclass it is well worth a read: https://arrow-kt.io/docs/0.10/apidocs/arrow-core-data/arrow.typeclasses/-traverse/Jannis
07/21/2020, 1:39 PMsequence(Either.applicative()).fold({ emptyList() }, ::identity)
(might need some type parameters though)Sagar Suri
07/21/2020, 1:45 PMSagar Suri
07/21/2020, 2:05 PMSagar Suri
07/21/2020, 2:05 PMJannis
07/21/2020, 2:08 PMsequence
will use ap
to combine the Either
's in the list. This means it will short circuit on a Left
. Note that it returns Either<E, List<A>>
. If you want to concatenate all values ignoring failure you can use filterMap
instead to do something like this: filterMap { it.toOption() }
Sagar Suri
07/21/2020, 2:21 PMSagar Suri
07/21/2020, 2:21 PMJakub Pi
07/21/2020, 3:43 PM