0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-18 10:41:29 -05:00

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 keys default]
(assert (vector? keys) "keys expected to be a vector")
`(let [v# (-> ~target ~@(map (fn [key] (list `c/get key)) keys))]
(if (some? v#) v# ~default))))
(let [last-index (dec (count keys))]
`(-> ~target ~@(map-indexed (fn [index key]
(if (= last-index index)
(list `c/get key default)
(list `c/get key)))
keys)))))
(defmacro str
[& params]