Re: simple procedure for updating a value one level down

2015-01-26 Thread Josh Stratton
This is my current solution. Again, it works fine, but seems a little verbose. I have a function called update-item, which has to call update-item-in-category with the same parameters plus the category I'm currently mapping through. On Jan 26, 2015 8:11 AM, "Lucas Bradstreet" wrote: > Given these

Re: simple procedure for updating a value one level down

2015-01-26 Thread Lucas Bradstreet
Given these points I would probably just do: (defn update-val-with-id [values m] (map (fn [v] (if (= (:id v) id) (merge v m) v)) values)) I'm not that happy with it either, so other suggestions are welcome. On 27 Janua

Re: simple procedure for updating a value one level down

2015-01-26 Thread Josh Stratton
They're not keyed by id because order in both the category and its items is important. I could maintain the order explicitly, but that just makes other problems like reordering more difficult. As a couple people have suggested I could access the page using vector indexing, but then I'd need to fig

Re: simple procedure for updating a value one level down

2015-01-26 Thread Michael Willis
Now that I think about it, I wonder why your categories aren't keyed by id, like this: (def categories [ {1 {:text "foo"} 2 {:text "bar" :ack 5}} {3 {:age 7}}]) Then the update-in can take the category id, instead of having to know its index within a vector: (update-in categories [1 3] merge

Re: simple procedure for updating a value one level down

2015-01-26 Thread Michael Willis
(def categories [ [ { :id 1 :text "foo" } { :id 2 :text "bar" :ack 5 } ] [ { :id 3 :age 7 } ] ]) #'user/categories (update-in categories [1 0] merge { :age 12 :somethingElse 29 }) [[{:text "foo", :id 1} {:text "bar", :ack 5, :id 2}] [{:age 12, :somethingElse 29, :id 3}]] On Monday, January 26,

Re: simple procedure for updating a value one level down

2015-01-26 Thread Erik Price
Many functions that affect keyed collections will work on vectors if you supply the numeric index as a key. e On Monday, January 26, 2015, Josh Stratton wrote: > I'm new to clojure and FP in general. One thing that has always been a > little confusing for me is working with immutable trees. I

Re: simple procedure for updating a value one level down

2015-01-25 Thread Lucas Bradstreet
Are you sure you want to return: [ [ { :id 1 :text "foo" } { :id 2 :text "bar" :ack 5 } ] [ { :id 3 :age 12 :somethingElse 29 } ] ] (notice the two nested vectors), or rather [ [ { :id 1 :text "foo" } { :id 2 :text "bar" :ack 5 } { :id 3 :age 12 :somethingElse 29 } ] ] Lucas On 26 January 2015 at

simple procedure for updating a value one level down

2015-01-25 Thread Josh Stratton
I'm new to clojure and FP in general. One thing that has always been a little confusing for me is working with immutable trees. I have a vector of categories, each category containing a vector of items--each one a hashmap. In that hashmap I have a bunch of attributes including an item-id. Now,