function
boot.janet on line 1836 , column 1
(update-in x ks f & args )
Update a value in `x` . Looks into a nested spot in `x` identified
by the keys `ks` and replaces the value found there with `f`
applied to that value and any values passed and available in
`args` . Missing spots will be replaced with tables and `f` is
passed `nil` instead of a found value. Returns `x` modified.
`x` can be a suitable array , table or abstract type with `get` and
`put` methods.
`ks` can be an indexed or abstract type with suitable `get` and
`length` methods.
(def ds @[@{:a 1 :b 2 }
@{:a 8 :b 9 }])
(defn thrice [x ] (* x 3 ))
(update-in ds [0 :b ] thrice )
# `ds` is now
@[@{:a 1 :b 6 }
@{:a 8 :b 9 }]
(defn ddup [ds ks val ]
(update-in ds ks
(fn [x ]
(if (= nil x )
@[val ]
(array/push x val )))))
(var a @{})
(ddup a [:a ] 1 )
(ddup a [:a ] 2 )
(ddup a [:a ] 3 )
# @{:a @[1 2 3]}
(update-in @{:a @{:b 1 }} [:a :b ] (fn [x ] (+ 1 x )))
# @{:a @{:b 2}}
(update-in @{:a 1 } [:a ] (fn [x ] (+ 1 x )))
# @{:a 2}