I have a value of this type:
List[Either[Error, Files]]
and I have a function which checks if there are any errors like this:
private def process(result: List[Either[Error, Files]]): Either[Error, List[Files]] = {
if(result.exists(p => p.isLeft)){
Left(Error("some downloads failed"))
}else{
Right(
Right(
result.collect {
case Right(value) => value
}
)
}
}
Is this the best way to return the List of files if there are no errors in result?