Created
November 1, 2017 16:09
-
-
Save hiredman/7d17d8d2b58c41ce95bf2db305b0f427 to your computer and use it in GitHub Desktop.
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
(require '[clojure.set :as set]) | |
(def info | |
[{:year 2017 | |
:month 4 | |
:data "x"} | |
{:year 2017 | |
:month 4 | |
:data "y"} | |
{:year 2017 | |
:month 7 | |
:data "z"}]) | |
(def db (reduce | |
(fn [db fact] | |
(merge-with into db | |
(set/index [fact] [:entity]) | |
(set/index [fact] [:entity :attribute]) | |
(set/index [fact] [:entity :attribute :value]) | |
(set/index [fact] [:attribute]) | |
(set/index [fact] [:attribute :value]) | |
(set/index [fact] [:value]))) | |
{} | |
(for [m info | |
:let [id (java.util.UUID/randomUUID)] | |
[k v] m] | |
{:entity id | |
:attribute k | |
:value v}))) | |
(for [{:keys [entity attribute value]} (get db {:attribute :month :value 4}) | |
{data :value} (get db {:entity entity :attribute :data})] | |
[entity data]) | |
;;=> ([#uuid "8ce5aaea-e633-4972-b8ef-3202680b2f6f" "y"] [#uuid "08d3e0ec-c08b-492e-b638-86fb2e932a93" "x"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment