Perhaps this is an overkill, but it comes to my mind :) (I'm new to clojure)

user=> (def mymap {:a (ref "foo") :b (ref "bar")})
#'user/mymap
user=> mymap
{:a #<Ref@987197: "foo">, :b #<Ref@497904: "bar">}
user=> (map #(dosync (ref-set %1 (repeat 2 (deref %1)))) (vals mymap))
(("foo" "foo") ("bar" "bar"))
user=> mymap
{:a #<Ref@987197: ("foo" "foo")>, :b #<Ref@497904: ("bar" "bar")>}


Stanislav Paskalev



On Wed, Feb 23, 2011 at 1:27 AM, Nurullah Akkaya <nurul...@nakkaya.com> wrote:
> You can use map to get your new sequence of pairs, the turn it into a 
> hash-map using into,
>
> (->> {:first "john" :last "smith" :age 25}
>  (map #(let [[k v] %]
> (if (string? v)
> [k (.toUpperCase v)] [k v])))
>  (into {}))
>
> Best,
> --
> Nurullah Akkaya
> http://nakkaya.com
> On Tuesday, February 22, 2011 at 5:08 AM, yair 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
>>
>
> --
> 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

-- 
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