On Wed, Jan 28, 2009 at 10:31 PM, Vincent Foley <vfo...@gmail.com> wrote:
>
> (-> person :employer :address :city) would be my pick

I tend to prefer this method as well. I find that doto and -> in
general are excellent tools for picking apart and poking nested
structures.

>
> Vincent
>
> On Jan 28, 4:02 pm, Mark Volkmann <r.mark.volkm...@gmail.com> wrote:
>> I have a map that describes a person.
>> It has a key that describes their address.
>> It also has a key for their employer.
>> The employer has its own address.
>>
>> (def person {
>>   :name "Mark Volkmann"
>>   :address {
>>     :street "644 Glen Summit"
>>     :city "St. Charles"
>>     :state "Missouri"
>>     :zip 63304}
>>   :employer {
>>     :name "Object Computing, Inc."
>>     :address {
>>       :street "12140 Woodcrest Executive Drive, Suite 250"
>>       :city "Creve Coeur"
>>       :state "Missouri"
>>       :zip 63141}}})
>>
>> Is this the best way to retrieve the employer city?
>> (reduce get person [:employer :address :city])
>>
>> Is this the best way to get a new map where the city is changed?
>> (update-in person [:employer :address :city] (fn [old & args] "Clayton"))
>> I can't get this to work with #("Clayton") in place of the anonymous
>> function above.

The function returned by constantly will take any number of arguments.

>>
>> --
>> R. Mark Volkmann
>> Object Computing, Inc.
> >
>



-- 
Venlig hilsen / Kind regards,
Christian Vest Hansen.

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