I have a couple utility functions I use a lot for creating maps from sequences and transforming one map to another. These are (poorly) named mapmap and mapmapmap. (Yes I know the names are awful but I have lived with them long enough that they've stuck.)
mapmap takes a key production function (optional - uses identity by default), a value production function, and a source sequence. (def c (range 5)) (mapmap #(+ 1 %) #(* 2 %) c) -> {5 8, 4 6, 3 4, 2 2, 1 0} More here: http://tech.puredanger.com/2010/09/24/meet-my-little-friend-mapmap/ mapmapmap is similar but takes a map, not a sequence. It applies the key function to transform the keys and the value function to transform the values. So your request would be: (mapmapmap #(if (string? %) (upper-case %) %) mymap) Here's a gist with the definition of both: https://gist.github.com/843292 Hope you find it useful... Alex On Feb 21, 9:08 pm, yair <yair....@gmail.com> wrote: > I'm hoping this is a dumb question and I've missed something obvious. > I have a map with various key-value pairs and I want to transform some > of the values, e.g. > > (def mymap {:first "john" :last "smith" :age 25}) and say I want to > change the strings to be upper case. > Right now all I can think of doing is using reduce and passing in an > empty map and the re-associating each key with the (possibly) > transformed value. Is there something like the map function that > takes two parameters, one a function that receives a pair and returns > a new pair, and the other a map, and returns a map that's > reconstituted from those pairs? > > Thanks -- 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