hrm, update-in isn't meant to be used that way.

Here's an example from clojuredocs:

user=> (def p {:name "James" :age 26})
#'user/p

user=> (update-in p [:age] inc)
{:name "James", :age 27}

;; remember, the value of p hasn't changed!
user=> (update-in p [:age] + 10)
{:name "James", :age 36}


The second arg is like a 'path' to the value to update.

In your code, here:      (commute items #(remove (fn [x](= (:id x) id)) %))

Seems like % might have started out as a vector, but it gets returned as a
seq.  That's the first thing to fix, seqs don't have keys.

Vectors have integer keys, but my intuition says you probably want to be
storing a map of ids to records, in which case, something like:

(commute items #(update-in % [:id] (fn [my-record]
(do-something-that-returns-a-new-record my-record))))

and your use of 'remove' could simply be a dissoc by id.




On Tue, Apr 8, 2014 at 6:14 PM, Ivan Schuetz <ivanschu...@gmail.com> wrote:

> Ahh dataprovider/products should be "items". Forgot to "simplify".
>
>
> Am Mittwoch, 9. April 2014 00:12:48 UTC+2 schrieb Ivan Schuetz:
>
>> Hi,
>>
>> sorry I don't get it. I just started learning Clojure.
>>
>> I did this to remove element with id 1
>>
>>      (commute items #(remove (fn [x](= (:id x) id)) %))
>>
>> From your statement I understand update-in would work for the update, but
>> I don't know the syntax. Something like
>>
>>     (commute dataprovider/products #(update-in % {:id id}  (->Item ???) ))
>>
>>
>>
>>
>> Am Mittwoch, 9. April 2014 00:01:00 UTC+2 schrieb Gary Trakhman:
>>>
>>>
>>>> But 1. Can't find examples with records, 2. Not sure if I can use it to
>>>> update a different field than the one I'm using to do the query. In the
>>>> examples fields seem to be the same.
>>>>
>>>>
>>>>
>>> Leave off the last path segment and return the full updated record, not
>>> just the new field's value.
>>>
>>  --
> 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