Improve dm/get-in macro to be fully compliant with core/get-in

This commit is contained in:
Andrey Antukh 2022-04-21 09:43:54 +02:00
parent 5eb53da374
commit 9e940dc042

View file

@ -34,8 +34,12 @@
`(-> ~target ~@(map (fn [key] (list `c/get key)) keys))) `(-> ~target ~@(map (fn [key] (list `c/get key)) keys)))
([target keys default] ([target keys default]
(assert (vector? keys) "keys expected to be a vector") (assert (vector? keys) "keys expected to be a vector")
`(let [v# (-> ~target ~@(map (fn [key] (list `c/get key)) keys))] (let [last-index (dec (count keys))]
(if (some? v#) v# ~default)))) `(-> ~target ~@(map-indexed (fn [index key]
(if (= last-index index)
(list `c/get key default)
(list `c/get key)))
keys)))))
(defmacro str (defmacro str
[& params] [& params]