Hi, I have an usecase, where I want to convert a l...
# arrow
p
Hi, I have an usecase, where I want to convert a list of entities to another entities. It is possible that this conversion results in an exception. If so I want to record the error, ignore the item and continue mapping. After the operation, I want to have a List of errors and a List of converted entities. I can think of using fold with two persistent list accumulators. Do you see a better way of doing something like this? Thanks
s
Hey @Petr Laštovička, You can use
Either
for this with
seperateEither
. https://arrow-kt.io/docs/apidocs/arrow-core/arrow.core/separate-either.html Something like this:
Copy code
fun convert(): Either<Throwable, Entity> =
  Either.catch { ... }

val (errors, entities) = list.map { convert() }
    .seperateEither()
p
Very cool, thanks arrow
s
My pleasure ☺️