Xuc Xiem
06/06/2020, 10:19 PMval eitherList: List<Either<Exception, String>> = TODO()
to a List<String>
? Someone on StackOverflow (I think) suggested:
eitherList
.filterIsInstance<Either.Right<String>>()
.fold(emptyList()) { acc, right -> right.fold({ acc }, { acc + it }) }
Is there any better way?Tesserakt
06/06/2020, 11:36 PMeitherList.filterMap { it.toOption() }
Use suitable overload of toOption
to not get Option<Either<..., ...>> 😄