How to convert this list `val eitherList: List<...
# arrow
x
How to convert this list
val eitherList: List<Either<Exception, String>> = TODO()
to a
List<String>
? Someone on StackOverflow (I think) suggested:
Copy code
eitherList
  .filterIsInstance<Either.Right<String>>()
  .fold(emptyList()) { acc, right -> right.fold({ acc }, { acc + it }) }
Is there any better way?
t
This should work:
Copy code
eitherList.filterMap { it.toOption() }
Use suitable overload of
toOption
to not get Option<Either<..., ...>> 😄
👏🏾 2
🙏 2