specter 2025-05-14

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.

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))))

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

🙌 1

you could also collapse in your solution the if to just

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