Clojure

clojure.walk/stringifiy-keys does not stringify non-keyword keys

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Declined
  • Affects Version/s: Release 1.4
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

The doc says "Recursively transforms all map keys from keywords to strings." however only those keys that pass keyword? get transformed to string. This leaves other keys such as java.Long as-is.

A simple fix would be

(defn stringify-keys*
"Recursively transforms all map keys from keywords to strings."
[m]
(let [f (fn [[k v]] (if (keyword? k) [(name k) v] [(str k) v]))]
;; only apply to maps
(postwalk (fn [x] (if (map? x) (into {} (map f x)) x)) m)))

Activity

Hide
Andy Fingerhut added a comment -

Closing as declined, since submitter agrees that code behavior and documentation match.

Show
Andy Fingerhut added a comment - Closing as declined, since submitter agrees that code behavior and documentation match.
Hide
Joel Kuiper added a comment -

You're right.
Somehow I parsed the doc string wrongly. My sincere apologies! Can be marked invalid.

Show
Joel Kuiper added a comment - You're right. Somehow I parsed the doc string wrongly. My sincere apologies! Can be marked invalid.
Hide
Andy Fingerhut added a comment -

It appears from the doc string that this function does exactly what it claims it will do, without any changes.

Show
Andy Fingerhut added a comment - It appears from the doc string that this function does exactly what it claims it will do, without any changes.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: