Fork me on GitHub
#specter
<
2022-05-11
>
pinkfrog13:05:12

Hi. I wonder if there is some update-in variant (in specter) that could well handle the case that when m is an empty map (see the following code snippet).

;; `m` is in the shape: {:a [ {:x [ 1,2,3 ,,,]} 
  ;;                            {:x [ 5,6,7 ,,,]}
  ;;                            ,,, }

  ;; the key `:a` and `:x` are fixed.  
  
  ;; i normally append number to certain [n1,n2,n3,,,] number list.
  ;; For example, append 6 to the 1st [numbers] list.
  (let [m {:a [{:x [1 2 3]}
               {:x [4 5]}]}]
    (update-in m [:a 1 :x] (fnil conj []) 6))

  ;; The question is:
  ;; what if `m` is initially `{}`, or `{:a []}` ? 
  ;; (update-in m [:a 0 :x] (fnil conj []) 6)) does not give the result: `{:a [{:x [6]}]}
`