Created
May 25, 2015 20:56
-
-
Save jtmarmon/0a644fbca15a1742964c to your computer and use it in GitHub Desktop.
Convert datomic entity map into clojure map
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn emap-to-hash-map [e] | |
(cond | |
(or | |
(-> e class .toString (clojure.string/split #" ") second (= "datomic.query.EntityMap")) | |
(map? e)) (reduce-kv (fn [m k v] (assoc m k (emap-to-hash-map v))) {} (into {} e)) | |
(coll? e) (map emap-to-hash-map e) | |
:else e)) |
I have found this function to work better:
(defn export-entity
[entity]
(clojure.walk/prewalk
(fn [x]
(if (instance? datomic.query.EntityMap x)
(into {} x)
x))
entity))
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Both
(instance? datomic.query.EntityMap e)
and(= (class e) datomic.query.EntityMap)
work and are faster than splitting the class name with a regex.Your solution also fails to consider the
many
cardinality situation, the element may be a set of datomic entities which you need to traverse.