Merge release Beta 1 into stable #21

Merged
Felisp merged 35 commits from dev into stable 2024-08-13 17:48:09 +02:00
2 changed files with 17 additions and 13 deletions
Showing only changes of commit 68a74cf1b8 - Show all commits

View file

@ -41,13 +41,15 @@
[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)]
(defn map-apply-defaults
"Apply default values from [defaults] to keys not present in [conf]
Order is very important.
Thus all missing values from config are replaced by defaults"
[conf defaults]
(into conf
(for [k (keys defaults)]
(let [val1 (get conf k)
val2 (get defaults k)]
(if (and (map? val1)
(map? val2))
{k (map-deep-merge-missing val1 val2)}

View file

@ -2,11 +2,13 @@
(:require [clojure.test :refer :all]
[rss-thread-watch.utils :refer :all]))
(defn first-map {:a :b
:c "c"
})
(def first-map {:a :b
:c "c"})
(def empty-map {})
(deftest map-deep-merge-missing-test
(testing "Map deep merge missing"
(is ())))
(testing "Default values in place of missing keys"
(is (= first-map (map-apply-defaults first-map empty-map))
"No defaults should return conf map unchanged")
(is (= first-map (map-apply-defaults empty-map first-map))
"Empty map should be completely replaced by defaults")))