[GHC] #974: Add partitionEithers, lefts, rights to Data.Either

Ross Paterson ross at soi.city.ac.uk
Thu Nov 9 03:50:41 EST 2006

On Fri, Nov 03, 2006 at 09:57:35AM -0500, roconnor at theorem.ca wrote:
> I have attached a new patch to the trac that now uses the identifier 
> partitionEithers.

I'd suggest also having the following variant, by analogy with mapMaybe:

-- | Map values and separate the 'Left' and 'Right' results.
mapEither :: (a -> Either b c) -> [a] -> ([b], [c])
mapEither f = foldr (add . f) ([], [])
  where add (Left b)  (bs, cs) = (b:bs, cs)
        add (Right c) (bs, cs) = (bs, c:cs)

More information about the Libraries mailing list