Oops - clicked wrong button (why doesn't gmail have paredit!) - sorry...

(defn transform [graphs]
  (let [
            ;; map of {:id customer}
            customers (load-customers-by-id graphs)
        ]

  (defn resolve-customer [g] (assoc g :customer ((:customer g) customers))))
  (defn switch-date-to-ms [g] (assoc :date (.getTime g))

  (into [] (for [g graphs] (resolve-customer (switch-date-to-ms g)))
)

Now this works except for the fact I have multiple decorators which work on
a graph which might be 5 levels deep and looks horrible :).

Any advice/guidance?

Thanks!

Col

P.S.  Where is the best place to get the "clojure 101" type help?  I feel
this type of request is almost "noise" for this mailing list....

On 11 November 2011 10:42, Colin Yates <[email protected]> wrote:

> Hi all,
>
> What is the idiomatic way to decorate a nested graph with multiple
> decorators?  Let me explain:
>
> I have a list of graphs:
>
> [
> {  :id 1
>   propertyA: {:customer 1 :name whatever :created (Date.)}
>   propertyB: {:customer 1 :created (Date.) :someOtherProperty 13}
> }
> ]
>
> After creating this graph (and only after, not before), I can now retrieve
> all the customers I need and create map (using group-by) of customerId:
> customer.  I also want to replace all the Dates to millisecondsSinceEpoch.
>  Just for fun I also want to decorate all instances of propertyA (but not
> propertyB) with an extra property.
>
> Some contraints: I cannot decorate each item at the time it is being
> loaded.  For example, I need to load the entire graph to identify which
> customers are needed, which I can then load in one batch.  I can't load all
> the customers because there are a gazillion of them.
>
> What I am currently doing is a wonderfully complex combination of defining
> each decorator as a separate function and then using nested fors.
>  Something like:
>
> (defn transform [graphs]
>   (let [
> customers (load-customers-by-id graphs)
>         ]
>
>   (defn resolve-customer [g] (assoc g :customer ((:customer g) customers)
> )
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to