<div>I&#39;d like to add foldMapWithKey to Data.Map and Data.IntMap.</div><div><br></div><div>Right now you can <font face="courier new, monospace">foldrWithKey</font> and <font face="courier new, monospace">foldlWithKey</font> on Data.Map and Data.IntMap, but you cannot foldMapWithKey.</div>
<div><br></div><div>You can fake this by using <font face="courier new, monospace">fold . mapWithKey</font> but this requires converting the entire structure. </div><div><br></div><div>You can also implement it with <font face="courier new, monospace">traverseWithKey</font> and the use of the <font face="courier new, monospace">Const</font> Monoid in a manner similar to <font face="courier new, monospace">foldMapDefault</font>.</div>
<div><br></div><div>When you have a monoid that can take advantage of the balanced nature of the tree, it&#39;d be nice to be able to not lose the original near balanced parenthesization of the source tree.</div><div><br>
</div><div>We can use this in the lens library for more efficient zippers on these containers, but in general having access to a &#39;balanced&#39; foldMap is useful for any such container, and it seems odd not to be able to get at the keys in this orientation when you can go so every other way.</div>
<div><br></div><div>A patch that implements the proposed operation is available here:</div><div><br></div><div><a href="https://github.com/haskell/containers/pull/24">https://github.com/haskell/containers/pull/24</a></div>
<div><br></div><div>Discussion Period: 2 weeks</div><div><br></div><div>-Edward</div>