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

Ross Paterson ross at soi.city.ac.uk
Thu Nov 9 11:39:59 EST 2006


On Thu, Nov 09, 2006 at 04:29:09PM +0100, Henning Thielemann wrote:
> On Thu, 9 Nov 2006, Ross Paterson wrote:
> > 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)
> 
> After my turnaround
>  http://www.haskell.org/pipermail/libraries/2006-November/006204.html
>   that's what I called partitionEither. From a 'map' function I expect a
> similarity to 'fmap', e.g. that the main input and the output have the
> same type constructor (here []).

As I said before, it's a bit of both map and partition, in the same way
that mapMaybe combines map and filter.  But mapMaybe is already there,
and this naming follows it.



More information about the Libraries mailing list