[Haskell-cafe] Data.Map: Values to keys and keys to values

Dmitri O.Kondratiev dokondr at gmail.com
Thu Jun 16 15:52:42 CEST 2011


On Thu, Jun 16, 2011 at 5:38 PM, Johan Tibell <johan.tibell at gmail.com>wrote:

> On Thu, Jun 16, 2011 at 3:01 PM, Dmitri O.Kondratiev <dokondr at gmail.com>
> wrote:
> > Hi,
> > Data.Map has many great functions, yet I could not find the one that
> allows
> > from one map create another map where keys are values and values are keys
> of
> > the first one.
> > Something like:
> > transMap:: (Ord k, Ord a) => Map k a -> Map a k
>
> I don't think implementing this function in the library would add much
> as it cannot be implemented more efficiently with access to the
> internal representation than it can using the public API. Just write
>
>    transMap = M.fromList . map swap . M.toList
>
> and stick it in some utility file.
>
> Johan
>


Yes, this is a good one. Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110616/6f127f9e/attachment.htm>


More information about the Haskell-Cafe mailing list