Fred Friis
07/16/2019, 3:27 AMval 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>
})
})