https://kotlinlang.org logo
#arrow
Title
# arrow
d

daneko

01/04/2019, 6:44 AM
Could you tell me how to convert from
List<Either<A,B>>
to
Either<A,List<B>>
. until 0.8.1, I used
ListK.sequence
.
Copy code
val src = List<Either<A,B>>
// 0.8.1
// import arrow.data.sequence
val result: Either<A, List<B>> = src.k().sequence(Either.applicative()).fix()

// 0.8.2
// which is the preferred ? or another solution?

// use ListK#traverse
val result: Either<A, List<B>> = src.k().traverse(Either.applicative(), ::identity).fix()

// import arrow.instances.listk.traverse.sequence
// import arrow.instances.either.functor.map
val result: Either<A, List<B>> = src.k().sequence(Either.applicative()).map{ it.fix() }