From bb02765233ece0e578d39631f90591f5c62d6714 Mon Sep 17 00:00:00 2001 From: Felisp Date: Fri, 5 Jan 2024 14:30:27 +0100 Subject: [PATCH] Added function for merging default board-config with custom parts Very important in the future. Needs mega testing, I even started writing tests because of this. --- src/rss_thread_watch/utils.clj | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/rss_thread_watch/utils.clj b/src/rss_thread_watch/utils.clj index fa95d4f..13944fd 100644 --- a/src/rss_thread_watch/utils.clj +++ b/src/rss_thread_watch/utils.clj @@ -9,6 +9,18 @@ [pred coll] (keep-indexed #(when (pred %2) %1) coll)) +(defn map-deep-merge-missing + "Merges two maps but only keys missing from first map" + [m1 m2] + (into m1 + (for [k (keys m2)] + (let [val1 (get m1 k) + val2 (get m2 k)] + (if (and (map? val1) + (map? val2)) + {k (map-deep-merge-missing val1 val2)} + {k (nil?-else val2 val1)}))))) + ;; ===== Macros ===== (defmacro nil?-else "Return x unless it's nil, the return y"