I have the following method:
firstRightOrLefts :: [Either b a] -> Either [b] a
firstRightOrLefts eithers =
case partitionEithers eithers of
(_, (x : _)) -> Right x
(xs, _) -> Left xs
What bothers me is the ugly pattern matching and I was wondering if there was a more idiomatic way to write this method. The idea is that I have a bunch of computations that can return Eithers and I just want to get the first result or all of the error messages. Maybe I'm using the wrong data structure. Maybe the Writer monad would be better suited to this task. I'm really not sure at this point. Cheers for any help!