Skip to content

Commit

Permalink
Add syntax sugar to deprofile function
Browse files Browse the repository at this point in the history
  • Loading branch information
weavejester committed Sep 27, 2024
1 parent 779e209 commit db14e14
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/integrant/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,10 @@
ordered collection of profile keys. The profile keys will be tried on each
profile in order until the profile returns a match. If there is no match, a
exception will be thrown."
[coll profile-keys]
(walk/postwalk #(if (profile? %) (deprofile-1 % profile-keys) %) coll))
([profile-keys]
#(deprofile % profile-keys))
([coll profile-keys]
(walk/postwalk #(if (profile? %) (deprofile-1 % profile-keys) %) coll)))

(defn- normal-map? [x]
(and (map? x) (not (reflike? x))))
Expand Down
14 changes: 13 additions & 1 deletion test/integrant/core_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
(defmethod ig/expand-key ::mod-c [_ v] {::c {:x {:y {:z v}}}})
(defmethod ig/expand-key ::mod-z [_ v] {::z v})

(defmethod ig/expand-key ::mod-prof [_ v]
{::a (ig/profile :dev {:dev v}, :test {:test v})})

(defmethod ig/init-key ::default [k v]
(swap! log conj [:init k v])
[v])
Expand Down Expand Up @@ -705,4 +708,13 @@
(is (= (ig/profile {:a 1})
(ig/profile :a 1)))
(is (= (ig/profile {:a 1, :b 2})
(ig/profile :a 1 :b 2)))))
(ig/profile :a 1 :b 2)))
(let [p (ig/profile :a 1)]
(is (= (ig/deprofile p [:a])
((ig/deprofile [:a]) p)))))

(testing "expand and deprofile"
(is (= (ig/expand {::mod-prof 1} (ig/deprofile [:dev]))
{::a {:dev 1}}))
(is (= (ig/expand {::mod-prof 2} (ig/deprofile [:test]))
{::a {:test 2}}))))

0 comments on commit db14e14

Please sign in to comment.