Skip to content

Instantly share code, notes, and snippets.

@shaunxcode
Last active December 20, 2015 00:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shaunxcode/6043282 to your computer and use it in GitHub Desktop.
Save shaunxcode/6043282 to your computer and use it in GitHub Desktop.
utilities for going between vector and map form of datomic query
(def query '[:find ?e ?fname ?lname
:in $ ?fname ?lname
:where [?e :user/firstname ?fname]
[?e :user/lastName ?lname]])
(defn group-by-kw [v]
(map (fn [[[f] l]] (conj [f] l))
(partition 2 (partition-by keyword? v))))
(defn query-vec-as-map [vquery]
(into {} (group-by-kw vquery)))
(defn query-map-as-vec [mquery]
(vec (apply concat
(map (fn [[f fr]] (cons f fr))
(into [] mquery)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment