
I'd like to propose the following additions to Data.Map (and IntMap): -- | /O(n)/. Map values and collect the 'Just' results. mapMaybe :: Ord k => (a -> Maybe b) -> Map k a -> Map k b -- | /O(n)/. Map keys\/values and collect the 'Just' results. mapMaybeWithKey :: Ord k => (k -> a -> Maybe b) -> Map k a -> Map k b -- | /O(n)/. Map values and separate the 'Left' and 'Right' results. mapEither :: Ord k => (a -> Either b c) -> Map k a -> (Map k b, Map k c) -- | /O(n)/. Map keys\/values and separate the 'Left' and 'Right' results. mapEitherWithKey :: Ord k => (k -> a -> Either b c) -> Map k a -> (Map k b, Map k c)

On Fri, Aug 11, 2006 at 03:24:18PM +0200, Henning Thielemann wrote:
On Fri, 11 Aug 2006, Ross Paterson wrote:
-- | /O(n)/. Map values and separate the 'Left' and 'Right' results. mapEither :: Ord k => (a -> Either b c) -> Map k a -> (Map k b, Map k c)
Looks more like 'partition' than 'map'.
It's a bit of both, in the same way as mapMaybe (from Data.Maybe) combines map and filter.

On Fri, 11 Aug 2006, Ross Paterson wrote:
On Fri, Aug 11, 2006 at 03:24:18PM +0200, Henning Thielemann wrote:
On Fri, 11 Aug 2006, Ross Paterson wrote:
-- | /O(n)/. Map values and separate the 'Left' and 'Right' results. mapEither :: Ord k => (a -> Either b c) -> Map k a -> (Map k b, Map k c)
Looks more like 'partition' than 'map'.
It's a bit of both, in the same way as mapMaybe (from Data.Maybe) combines map and filter.
How would you name a function with signature ??? :: Ord k => (a -> Maybe b) -> Map k a -> (Map k a, Map k b) which returns the list of elements that resulted in Nothing and the list of elements that could be translated to Just? It holds mapMaybe f = snd . ??? f
participants (2)
-
Henning Thielemann
-
Ross Paterson