Skip to content

Commit

Permalink
contrib.data: unqualified-keys
Browse files Browse the repository at this point in the history
  • Loading branch information
dustingetz committed Sep 13, 2024
1 parent 673ac88 commit 00b04e0
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/contrib/data.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@
(unqualify nil) := nil
(unqualify "") :throws #?(:clj AssertionError :cljs js/Error))

(defn unqualified-keys [m] (update-keys m unqualify))

(tests
(unqualified-keys {::a ::a}) := {:a ::a}
(unqualified-keys {:a/x 1 :b/x 2}) := {:x 2} ; gotcha
(unqualified-keys {}) := {}
(unqualified-keys nil) := {}
(unqualified-keys {nil ::a}) := {nil ::a}
;(unqualified-keys {1 ::a}) := {:a ::a} -- Assert failed: can't unqualify: 1
;(unqualified-keys {{} ::a}) := {:a ::a} -- Assert failed: can't unqualify: {}
)

(defn -omit-keys-ns [ns ?m]
{:pre [(some? ns)]}
(when ?m
Expand Down

0 comments on commit 00b04e0

Please sign in to comment.