[Haskell-cafe] ANN: unordered-container

Joachim Breitner mail at joachim-breitner.de
Sat Jun 4 15:09:39 CEST 2011


Am Samstag, den 04.06.2011, 14:23 +0200 schrieb Joachim Breitner:
> I was looking into using HashMap in a tool for the Debian Haskell Group
> that currently uses a somewhat large Map, but I found some functions
> missing that I was using:
>  * unions
>  * element
>  * unionWith
>  * mapWithKey

here are naive implementations using the current API, although I guess
better code can be created within unordered-container:

-- Functions from Data.Map missing in Data.HashMap
unions = foldl M.union M.empty
member k = isJust . M.lookup k
unionWith f m1 m2 = M.foldrWithKey (M.insertWith f) m1 m2
mapWithKey f = runIdentity . M.traverseWithKey (\k v -> Identity (f k v))


Joachim "nomeata" Breitner
  mail: mail at joachim-breitner.de | ICQ# 74513189 | GPG-Key: 4743206C
  JID: nomeata at joachim-breitner.de | http://www.joachim-breitner.de/
  Debian Developer: nomeata at debian.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110604/00bfdce5/attachment.pgp>

More information about the Haskell-Cafe mailing list