[GHC] #974: Add partitionEithers, lefts, rights to Data.Either
lemming at henning-thielemann.de
Thu Nov 9 10:29:09 EST 2006
On Thu, 9 Nov 2006, Ross Paterson wrote:
> 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)
After my turnaround
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 ).
More information about the Libraries