Open
Description
Currently there are functions
mapKeys :: (Ord k) => (j -> k) -> Map j a -> Map k a
traverse :: (Applicative f) => (a -> f b) -> Map k a -> f (Map k b)
but nothing of the type (Applicative f, Ord k) => (j -> f k) -> Map j a -> f (Map k a)
.
A sample implementation:
traverseKeys :: (Applicative f, Ord k) => (j -> f k) -> Map j a -> f (Map k a)
traverseKeys f = fmap fromList . traverse (\(j, a) -> (,a) <$> f j) . assocs
traverseKeysWith :: (Applicative f, Ord k) => (a -> a -> a) -> (j -> f k) -> Map j a -> f (Map k a)
traverseKeysWith c f = fmap (fromListWith c) . traverse (\(j, a) -> (,a) <$> f j) . assocs
which is O(n log n)
, if I'm not mistaken; though I haven't looked through the internals of the implementation to dig for further optimizations.