specter

Christian Dean 2025-05-14T13:59:42.492539Z

If I have a vector of strings, like this ["text" "text" "text"], and I have another empty vector which i want to transform to create maps for every string, like [{:key "text"} {:key "text"} {:key "text"}], how do I do that? The main constraint here is that i will also later add other keys to these maps, like [{:key "text" :other-key ""} {:key "text" :other-key ""} {:key "text" :other-key ""}], so I need a way to do this without removing or modifying the :other-keys in each map.

Christian Dean 2025-05-14T14:16:56.204679Z

This is how you do it without specter:

(def strings (r/atom ["text" "text" "text"]))
(def maps (r/atom []))

(defn sync-maps-with-strings! []
  (let [current-strings @strings
        current-maps @maps]

    
    (reset! maps
            (mapv
             (fn [idx s]
               (if (< idx (count current-maps))
                 ;; Update existing map
                 (assoc (nth current-maps idx) :key s)
                 
                 {:key s}))
             (range (count current-strings))
             current-strings))))

xificurC 2025-05-14T14:37:43.768169Z

doesn't look like a specter task. Here's what I would do

🙌 1
xificurC 2025-05-14T14:39:02.378469Z

you could also collapse in your solution the if to just

(assoc (nth current-maps idx {}) :key s)