Re: (newbie) replace certain values of a map based on a predicate

2013-07-12 Thread Colin Yates
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" wrote: > Even without reaching for libra

Re: (newbie) replace certain values of a map based on a predicate

2013-07-05 Thread Justin Kramer
Besides post-processing results, you can also instruct java.jdbc to return Joda dates in the first place. Using clojure.java.jdbc 0.3.0-alpha4: (ns example (:require [clojure.java.jdbc :as j] [clj-time.local :as cl])) ... (extend-protocol j/IResultSetReadColumn java.sql.Date (r

Re: (newbie) replace certain values of a map based on a predicate

2013-07-05 Thread Cedric Greevey
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? %) (t

Re: (newbie) replace certain values of a map based on a predicate

2013-07-05 Thread Ben Wolfson
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 wrote: > I had to do something similar, and used > clojure.walk. > > On Friday, July 5, 2013

Re: (newbie) replace certain values of a map based on a predicate

2013-07-05 Thread Colin Yates
Grrr.. google groups seems to be playing up so apologies if this is double posted. Thanks both! My attempt (inspired by Stuart Sierra's reply at https://groups.google.com/forum/#!topic/clojure/Hlfn4PdKg-k) was something like this (from memory so forgive me): (defn val-or-date [result [k v]] (

Re: (newbie) replace certain values of a map based on a predicate

2013-07-05 Thread Jim - FooBar();
I 'd change the implentation of update-vals to use reduce-kv. you will avoid the cost of destructuring on every single step :) Jim On 05/07/13 22:15, Jay Fields wrote: I use update-vals from https://github.com/jaycfields/jry fairly often. As long as you don't mind doing the pred check in the

Re: (newbie) replace certain values of a map based on a predicate

2013-07-05 Thread Jay Fields
I use update-vals from https://github.com/jaycfields/jry fairly often. As long as you don't mind doing the pred check in the fn you pass to update-vals, it should do the trick. Cheers, Jay On Fri, Jul 5, 2013 at 5:14 PM, Jim - FooBar(); wrote: > You'll never really 'replace' any values so why n

Re: (newbie) replace certain values of a map based on a predicate

2013-07-05 Thread Jim - FooBar();
You'll never really 'replace' any values so why not reduce/reduce-kv ? Just build a new map out of the old one... Jim On 05/07/13 21:59, 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

Re: (newbie) replace certain values of a map based on a predicate

2013-07-05 Thread John Walker
I had to do something similar, and used clojure.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 v

(newbie) replace certain values of a map based on a predicate

2013-07-05 Thread Colin Yates
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 s