[containers] Proposal: Add traverseKeys, traverseKeysWith, traverseKeysMonotonic to Data.Map

Niklas Haas haskell at nand.wakku.to
Tue Mar 11 01:24:21 UTC 2014


Hello all,

While programming a specific type of map update I came across a great
need for a 'traverseKeys' function. I ended up making it myself but it
was still less efficient than it needed to be because my traversal
function was actually monotonic.

I went ahead and added this along with some variants to Data.Map.

> traverseKeys :: (Applicative f, Ord k2) => (k1 -> f k2) -> Map k1 a -> f (Map k2 a)
> traverseKeysWith :: (Applicative f, Ord k2) => (a -> a -> a) -> (k1 -> f k2) -> Map k1 a -> f (Map k2 a)
> traverseKeysMonotonic :: (Applicative f, Ord k2) => (k1 -> f k2) -> Map k1 a -> f (Map k2 a)

A full patch can be found here:
https://github.com/nandykins/containers/commit/a8b0ebd57653bc0a309af69d732356e3572c455c

Let me know what you think,

Discussion period: 2 weeks


More information about the Libraries mailing list