Thanks Konrad.

I certainly do not want to add this to fmap. However, I think there  
are lots of situations where mapping keys is well-defined. For  
example, you have a tree of data from XML or JSON, and you want to  
replace the keys (strings) with instances of their actual type.

I guess given the ambiguity that names like "mapkeys" might be  
misleading. Other suggestions?

Stu

>
> On 30.05.2009, at 17:11, Stuart Halloway wrote:
>
>> clojure.contrib.generic.functor.fmap will return a map with values
>> updated by a function. What if I wany *keys* updated by a function?
>> Does this exist yet? If not, what should I name it for inclusion in
>> contrib?
>
> Speaking strictly from an implementation point of view, you could add
> a type tag to your map that identifies it as a "map for which fmap
> acts on keys", and implement the multimethod fmap for that type.
>
> However, transforming keys is a much less well-defined operation than
> transforming values. You can consider a map a function from keys to
> values; fmap then returns the composition of that function with an
> arbitrary function f. That's always well-defined. A transformation of
> keys can lead to ambiguities: what if two different keys are
> transformed to the same new key, but the associated values differ?
> For this reason, the operation you want does not satisfy the
> conditions for fmap.
>
> Finally, I don't know of any other module that implements such a
> function, perhaps because of the ambiguity problem.
>
> Konrad.
>
>
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to