1
0
mirror of https://github.com/janet-lang/janet synced 2024-12-11 09:10:27 +00:00
janet/examples/utils.dst

23 lines
718 B
Plaintext
Raw Normal View History

(defn put-in [coll keys val]
(defn assoc [the-coll n]
(if-let [current-key (get keys n)
current-val (get the-coll current-key)]
(put the-coll current-key (assoc current-val (inc n)))
val))
(assoc coll 0))
(defn update-in [coll keys an-fn]
(def new-keys (array-slice coll 0 -2) )
(def last-key (get (array-slice coll -1 -2) 0))
(defn assoc [the-coll n]
(if-let [current-key (get keys n)
current-val (get the-coll current-key)]
(put the-coll current-key (assoc current-val (inc n)))
( update the-coll last-key an-fn )))
(assoc coll new-keys 0))
;; (defn update-in-test [ ] (update-in @{:a "x" :b {:y {"pipa" 3}}} [:b :y "pipa"] type))