From 9e940dc042600b87abe907942c83e369c5ce6f05 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 21 Apr 2022 09:43:54 +0200 Subject: [PATCH] :sparkles: Improve dm/get-in macro to be fully compliant with core/get-in --- common/src/app/common/data/macros.cljc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/common/src/app/common/data/macros.cljc b/common/src/app/common/data/macros.cljc index af628cb0b..bdf9882b2 100644 --- a/common/src/app/common/data/macros.cljc +++ b/common/src/app/common/data/macros.cljc @@ -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]