
17 Oct
2013
17 Oct
'13
10:57 a.m.
Hi Lorenzo, all the nice abstractions like Functor, Traversable or Foldable operate on the values of the Map. So there's 'Data.Traversable.mapM', which almost does what you want, but only for the values of the Map. Ok, here's a solution that does what you want: import Data.Map import Control.Monad mapKeysM :: (Ord k1, Ord k2, Monad m) => (k1 -> m k2) -> Map k1 v -> m (Map k2 v) mapKeysM f map = return . fromList =<< mapM g (toList map) where g (key, value) = do key' <- f key return (key', value) Certainly there has to be a solution using the lens library ... Greetings, Daniel