My response had the assumption that this is an example of an X-Y problem :-).
If you want to literally do what you said, then you can't use update-in because the value at that point is a seq. If you have to continue in this way, for some reason, what you probably want is map-indexed, which provides the index of the element as one of the parameters to the mapping function. You could use a helper to build a function that only operates on that particular element. I caution that you might run into a stackoverflow due to laziness if you do this enough without realizing the seq. This just feels unidiomatic to me, though. On Tue, Apr 8, 2014 at 7:10 PM, Ivan Schuetz <ivanschu...@gmail.com> wrote: > As I said I already looked in the docs, and know these basic examples, but > I don't know how to do: > > *"How can I say in a vector of records e.g. "set name of element to "foo" > where id is equal 1"?"* > > > The remove by Id works, I posted it only to show something which might be > similar to the update I'm looking for. > > I also wrote filter: > > (nth (filtered (filter #(= (:id %) id) @dataprovider/products)) 0) > > This gives me the element I need to update, but I still don't know how I > update this element in the vector. > > > > Am Mittwoch, 9. April 2014 00:27:41 UTC+2 schrieb Gary Trakhman: >> >> Maybe this will help: >> >> > (update-in [[] 2 3 4] [0] (constantly 1)) >> [1 2 3 4] >> >> > (update-in [[] 2 3 4] [2] (constantly 1)) >> [ [ ] 2 1 4] >> >> > (update-in [[] 2 3 4] [1] (constantly 1)) >> [ [ ] 1 3 4] >> >> > (update-in [[] 2 3 4] [0 :a] (constantly :b)) >> java.lang.IllegalArgumentException: Key must be integer >> >> > (update-in [[] 2 3 4] [0 0 :a] (constantly :b)) >> [ [{:a :b}] 2 3 4] >> >> >> On Tue, Apr 8, 2014 at 6:22 PM, Ivan Schuetz <ivans...@gmail.com> wrote: >> >>> I would use merge to update the record with the map... but I don't know >>> how to get it from filter operation. Maybe I should not solve this with >>> 1-liner. >>> >>> Am Mittwoch, 9. April 2014 00:14:09 UTC+2 schrieb Ivan Schuetz: >>> >>>> 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 clo...@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+u...@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+u...@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. > -- 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.