Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you think your data as a tree structure (of n levels) and you need to replace the "underscore" for the "dash" character of the tree structure's keys, then you can try to solve this functionality using the library designed for: <a href="http://richhickey.github.io/clojure/clojure.walk-api.html" rel="nofollow noreferrer">clojure.walk</a> </p> <p>Actually <strong>clojure.walk</strong> brings a similar functionality <a href="http://richhickey.github.io/clojure/clojure.walk-api.html#clojure.walk/keywordize-keys" rel="nofollow noreferrer">keywordize-keys</a></p> <pre><code>(defn keywordize-keys "Recursively transforms all map keys from strings to keywords." {:added "1.1"} [m] (let [f (fn [[k v]] (if (string? k) [(keyword k) v] [k v]))] ;; only apply to maps (postwalk (fn [x] (if (map? x) (into {} (map f x)) x)) m))) </code></pre> <p>Then you only have to change the <a href="http://clojuredocs.org/clojure_core/clojure.core/keyword" rel="nofollow noreferrer">keyword</a> function for the clojure.string/<a href="http://clojuredocs.org/clojure_core/clojure.string/replace" rel="nofollow noreferrer">replace</a> function</p> <p>and this is the result:</p> <pre><code>(defn underscore-to-dash-string-keys "Recursively transforms all map keys from strings to keywords." {:added "1.1"} [m] (let [f (fn [[k v]] (if (string? k) [(clojure.string/replace k "_" "-") v] [k v]))] ;; only apply to maps (clojure.walk/postwalk (fn [x] (if (map? x) (into {} (map f x)) x)) m))) (underscore-to-dash-string-keys {"_a" 1 "_b" 2 "_c" 3}) =&gt; {"-a" 1, "-b" 2, "-c" 3} </code></pre> <p>Related to this question : <strong>How best to handle the mapping of Cassandra column names to Clojure variables?</strong> I think it is well discussed here <a href="https://stackoverflow.com/questions/9345056/in-clojure-how-to-destructure-all-the-keys-of-a-map">In Clojure, how to destructure all the keys of a map?</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload