Last active
December 20, 2015 00:39
-
-
Save shaunxcode/6043282 to your computer and use it in GitHub Desktop.
utilities for going between vector and map form of datomic query
This file contains 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
(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