Skip to content

Commit

Permalink
Merge pull request #113 from macielti/unamespaced-map-function
Browse files Browse the repository at this point in the history
 Add misc function to remove namespace from keywords in a map
  • Loading branch information
macielti authored Jul 25, 2024
2 parents 30fc2d0 + 68901b8 commit fed0632
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ of [keepachangelog.com](http://keepachangelog.com/).

## [Unreleased]

## [25.52.51] - 2024-07-25

## Added

- Add misc function to remove namespace from keywords in a map.

## [25.52.50] - 2024-07-21

## Added
Expand Down Expand Up @@ -689,7 +695,9 @@ of [keepachangelog.com](http://keepachangelog.com/).

- Add `loose-schema` function.

[Unreleased]: https://github.com/macielti/common-clj/compare/v25.52.50...HEAD
[Unreleased]: https://github.com/macielti/common-clj/compare/v25.52.51...HEAD

[25.52.51]: https://github.com/macielti/common-clj/compare/v25.52.50...v25.52.51

[25.52.50]: https://github.com/macielti/common-clj/compare/v25.51.50...v25.52.50

Expand Down
2 changes: 1 addition & 1 deletion doc/components/cronjob.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ After that you need to add the cronjob component to your system map:
(def system
(component/system-map
:cronjob (component.cronjob/new-cronjob <<tasks>>)))
```
```
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject net.clojars.macielti/common-clj "25.52.50"
(defproject net.clojars.macielti/common-clj "25.52.51"
:description "Just common Clojure code that I use across projects"
:url "https://github.com/macielti/common-clj"
:license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
Expand Down
12 changes: 12 additions & 0 deletions src/common_clj/misc/core.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(ns common-clj.misc.core
(:require [common-clj.keyword.core :as common-keyword]
[schema.core :as s]
[clojure.walk :refer [postwalk]]))

(s/defn un-namespaced :- (s/pred map?)
"Recursively un-namespace map keys"
[schema :- (s/pred map?)]
(postwalk (fn [x]
(if (keyword? x)
(common-keyword/un-namespaced x)
x)) schema))
15 changes: 15 additions & 0 deletions test/unit/common_clj/misc/core_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
(ns common-clj.misc.core-test
(:require [clojure.test :refer :all]
[common-clj.misc.core :as misc]
[schema.test :as s]))

(s/deftest un-namespaced-test
(testing "Given a map with namespaced keys, it should return a map with un-namespaced keys"
(is (= {:a 1 :b 2}
(misc/un-namespaced {:test/a 1 :test/b 2})))

(is (= {:a 1 :b :key}
(misc/un-namespaced {:test/a 1 :test/b :namespaced/key})))

(is (= {:a 1 :b [:first :second]}
(misc/un-namespaced {:test/a 1 :test/b [:namespaced/first :namespaced/second]})))))

0 comments on commit fed0632

Please sign in to comment.