Consider this map:
(def my-map {:a-vec []}) Now I want to append some value to a-vec:
(assoc my-map :a-vec (conj (:a-vec my-map) 17)) What I don't like about this is that I name both the map and the key twice.
In actual code I have this function:
(defn update-game-objects [objs col-key brick] (-> objs (assoc col-key (conj (col-key objs) brick)) ; <- check here (update-in [:temp :x] inc))) Notice how I explicitly access objs, the same one that is threaded through. This should be a big no-no and only works in this case, because it is on the first line of the threading macro. Otherwise I might undo changes to objs done before.
Regarding my first example again, ideally I would like to have a function like this:
(assoc-conj my-map :a-vec 17) I haven't found a function like this, but is there another way to append to a vector inside a map, referencing the map and the key only once?