Skip to content

Instantly share code, notes, and snippets.

@jtmarmon
Created May 25, 2015 20:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jtmarmon/0a644fbca15a1742964c to your computer and use it in GitHub Desktop.
Save jtmarmon/0a644fbca15a1742964c to your computer and use it in GitHub Desktop.
Convert datomic entity map into clojure map
(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))
@guilespi
Copy link

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.

@thomas-shares
Copy link

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