mat
12/08/2023, 11:23 PMval results = someList.map(this::createsEitherResultOrErrorDescription)
if (results.any {it.isRight() }) return Right() // GET ALL RIGHTS HERE
return Left(consumesListOfResults(results.map {}) // GET ALL LEFTS HERE
I have found this super ugly hack here for retrieving the lefts:
val results = results.map { it.merge() as MyResult }
But it's not very nice.
For the Right case there is Either.getOrNull(), but I don't see a value for LEfts anywhere.
In the ideal case there would be these two extension functions:
List<Either<A,B>>.getAllLefts(): List<A>
List<Either<A,B>>.getAllRights(): List<B>
mitch
12/09/2023, 1:01 AMfun List<Either<L, R>>.getLefts() =
buildList {
this@getLefts.forEach { either ->
either.onLeft { add(it) }
}
}
CLOVIS
12/09/2023, 10:57 AMval lefts = someList.filterIsInstance<Either.Left<A>>().map { it.value }
val rights = someList.filterIsInstance<Either.Right<B>>().map { it.value }
mat
12/10/2023, 9:18 PMsimon.vergauwen
12/12/2023, 8:12 AMval (lefts, rights) = someList.separateEither()
https://apidocs.arrow-kt.io/arrow-core/arrow.core/separate-either.html?query=fun%20%3C[…]3E.separateEither():%20Pair%3CList%3CA%3E,%20List%3CB%3E%3Emat
12/12/2023, 4:57 PMCLOVIS
12/12/2023, 4:57 PM