
On Thu, 9 Nov 2006, Ross Paterson wrote:
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.
I can write mapMaybe f . mapMaybe g but not mapEither f . mapEither g that's why I think, this kind of mapEither is not as much 'map' as 'mapMaybe' is. :-)