Hey fellas, I'm somewhat confused about the behaviour of Either. How do I retrieve the value out of a Left?
Basically, my code is this:
val 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>