in membership-common/src/main/scala/com/gu/memsub/subsv2/services/SubscriptionService.scala [25:37]
def apply[A](eitherList: List[String \/ A]): String \/ NonEmptyList[A] = {
val zero = (List[String](), List[A]())
val product = eitherList.foldRight(zero)({
case (-\/(left), (accuLeft, accuRight)) => (left :: accuLeft, accuRight)
case (\/-(right), (accuLeft, accuRight)) => (accuLeft, right :: accuRight)
})
// if any are right, return them all, otherwise return all the left
product match {
case (Nil, Nil) => -\/("no subscriptions found at all, even invalid ones") // no failures or successes
case (errors, Nil) => -\/(errors.mkString("\n")) // no successes
case (_, result :: results) => \/-(NonEmptyList.fromSeq(result, results)) // discard some errors as long as some worked (log it?)
}
}