After doing a match on a bunch of Eithers that have type Either[String, A] (where A is more than one type), I'd like to accumulate any strings on the left into a list.
(a, b, c, d, e) match {
case (Right(a), Right(b), Right(c), Right(d), Right(e)) => {
"All good, use a, b, c, d, and e!"
}
case anythingElse => {
val strings = accLefts(anythingElse)
doSomethingWithStrings(strings)
}
}
If I try to .productIterator.toList
the tuple, I end up with List[Any]. If I handle each failing case separately (combinations of Rights and Lefts), I end up with an exponential number of case statements.
How can I get a List[Either[String, Any]] at the end there to pass to my accLefts call? Or should I have done something other than a match?