Thanks Cedric,

I am constantly writing code and then finding something in the core library
whivh already does what I need :).

http://clojuredocs.org/clojure_core/1.2.0/clojure.walk/keywordize-keys was
the latest gem.
On 5 Jul 2013 22:51, "Cedric Greevey" <cgree...@gmail.com> wrote:

> Even without reaching for libraries outside clojure.core, there's
>
> (update-in m [:key-of-interest] #(if (condition? %) (transformation %) %))
>
> and the ability to convert that into a function, e.g.
>
> (defn conditional-update-in [m condition? transformation k]
>   (update-in m [k] #(if (condition? %) (transformation %) %)))
>
> and then, if you have many keys that should undergo the same
> transformation under the same condition,
>
> (reduce (partial conditional-update-in m condition? transformation)
> [keys...]), and its encapsulation,
>
> (defn conditional-update-multi [m condition? transformation ks]
>   (reduce (partial conditional-update-in m condition? transformation) ks))
>
>
>
>
> On Fri, Jul 5, 2013 at 5:31 PM, Ben Wolfson <wolf...@gmail.com> wrote:
>
>> You could use clojure.algo.generic.functor.fmap: (fmap #(if (pred? %)
>> replacement-value %) your-map).
>>
>>
>> On Fri, Jul 5, 2013 at 2:08 PM, John Walker <jouiswal...@gmail.com>wrote:
>>
>>> I had to do something similar, and used 
>>> clojure.walk.<http://clojuredocs.org/clojure_core/clojure.walk/walk>
>>>
>>> On Friday, July 5, 2013 8:59:54 PM UTC, Colin Yates wrote:
>>>>
>>>> Hi all,
>>>>
>>>> I think this is one of those questions which has quite a few answers,
>>>> but given a map, how do I replace the values by applying a function to
>>>> those values, but only if they meet a condition?
>>>>
>>>> I understand the building blocks of (map..), (filter..), (assoc-in..)
>>>> and (filter..) and I can see how something could work using those pieces
>>>> but is would be pretty verbose.  I am sure there is probably a much more
>>>> simple way using a more abstract function.
>>>>
>>>> The actual use case is I have a list of maps as returned from the
>>>> clojure.java.jdbc framework and they contain timestamps.  I want to replace
>>>> all the timestamps with (for example) to a Joda LocalDate using the
>>>> excellent clj-time library.
>>>>
>>>> Any pointers?
>>>>
>>>> Thanks!
>>>>
>>>> Col
>>>>
>>>  --
>>> --
>>> 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 unsubscribe from this group and stop receiving emails from it, send
>>> an email to clojure+unsubscr...@googlegroups.com.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>>
>>>
>>
>>
>>
>> --
>> Ben Wolfson
>> "Human kind has used its intelligence to vary the flavour of drinks,
>> which may be sweet, aromatic, fermented or spirit-based. ... Family and
>> social life also offer numerous other occasions to consume drinks for
>> pleasure." [Larousse, "Drink" entry]
>>
>>  --
>> --
>> 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 unsubscribe from this group and stop receiving emails from it, send an
>> email to clojure+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
>
>  --
> --
> 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 a topic in the
> Google Groups "Clojure" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/clojure/Wqu-VBR5bSk/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to