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 13:10, Josh Stratton <strattonbra...@gmail.com> 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 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,
> assuming I have an item id, what's the easiest way to update the appropriate
> hashmap?  I can't use an assoc, I believe, because my data is in a
> vector--not keyed by the id.
>
> What I have been doing is writing a function that maps the categories to new
> categories and then write another function that is called on every item and
> updates it iff the item id matches.  This works, but it seems really clunky
> and I'm assuming there's a simpler way to do it.
>
> ; categories is a vector of item vectors, where the item is a hash
> (def categories [ [ { :id 1 :text "foo" } { :id 2 :text "bar" :ack 5 } ] [ {
> :id 3 :age 7 } ] ])
>
> Is there a more elegant workflow for updating categories?  Let's say I want
> to update item of id 3 with { :age 12 :somethingElse 29 }, what's the
> easiest way to do this?
>
> ; so the return would be
> [ [ { :id 1 :text "foo" } { :id 2 :text "bar" :ack 5 } ] [ { :id 3 :age 12
> :somethingElse 29 } ] ]
>
> --
> 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/d/optout.

-- 
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/d/optout.

Reply via email to