Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dispatch for every implementation of IPersistentMap #701

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion modules/reitit-core/src/reitit/walk.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[m k v]
(assoc! m (if (string? k) (keyword k) (-keywordize k)) (-keywordize v)))

(defn- -keywordize-map
(defn- -keywordize-kvreducible
[m]
(persistent! (reduce-kv keywordize-kv (transient (empty m)) m)))

Expand All @@ -29,6 +29,14 @@
(doseq [type [clojure.lang.PersistentArrayMap
clojure.lang.PersistentHashMap
clojure.lang.PersistentTreeMap]]
(extend type IKeywordize {:-keywordize -keywordize-kvreducible}))

(defn- -keywordize-map
[m]
(let [f (fn [[k v]] (if (string? k) [(keyword k) v] [k v]))]
(into {} (map f) m)))

(doseq [type [clojure.lang.IPersistentMap]]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why doseq here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly because I copied the other implementation.
Makes it easier to extend to another type in the future

(extend type IKeywordize {:-keywordize -keywordize-map}))

(extend-protocol IKeywordize
Expand Down
Loading