Gopal S Akshintala
12/19/2020, 6:55 AMsequence. Is there a way to avoid 2 boilerplate `fix()`s in the below example to get that data type? Is there any on-going development on this, now that Kind is being deprecated?
val listOfOptionalNumbers: List<Either<Int, Int>> =
listOf(1.right(), 2.right(),3.right())
val result: Either<Int, List<Int>> =
listOfOptionalNumbers.sequence(Either.applicative()).map { it.fix() }.fix()Scott Christopher
12/19/2020, 11:14 AMfun <E, A> Iterable<Either<E, A>>.sequence(): Either<E, Iterable<A>> =
either.eager { this@sequence.map { it.bind() } }
listOf(1.right(), 2.right(), 3.right()).sequence()Scott Christopher
12/19/2020, 11:19 AMfun <E, A, B> Iterable<A>.traverse(f: (A) -> Either<E, B>): Either<E, Iterable<B>> =
either.eager { this@traverse.map { f(it).bind() } }
fun <E, A> Iterable<Either<E, A>>.sequence(): Either<E, Iterable<A>> =
this.traverse(::identity)simon.vergauwen
12/19/2020, 11:19 AMfix and by extension Kind.
This is the PR for Either. https://github.com/arrow-kt/arrow-core/pull/272simon.vergauwen
12/19/2020, 11:19 AMeither or either.eager works too as @Scott Christopher mentioned!