I implemented a similar outcome using a fold but i...
# arrow
f
I implemented a similar outcome using a fold but it's quite unreadable
Copy code
val eitherErrorOrListOfUsers = listOfEitherErrorOrUser
            .fold(
                Either.right(emptyList()), //initial: Either.right(emptyList<User>)
                { accumulator: Either<IError, List<User>>,
                  currentItem: Either<IError, User> ->
                    currentItem
                        .fold({
                            Either.left(it) //current item is error, set it to Either<here, List<User>>
                        }, { user ->
                            //current item is user
                            accumulator.map { list -> list.flatMap { listOf(user) } } //add it Either<Error, here>
                        })
                })