Thank you all for your input. I think I will follow Stuart's advice
and go with something like the following, again using the example data
above.

(use 'clojure.set)

(def policies (ref #{{:id 3 :name "x" :holder 7 :vehicle 11}
                              {:id 4 :name "y" :holder 2 :vehicle
12}}))

(def vehicles (ref #{{:id 11 :make "Audi" :driver 7}
                               {:id 12 :make "Toyota" :driver 2}}))

(def people (ref #{{:id 7 :name "Brenton"}
                            {:id 2 :name "John"}}))

(defn find-policy [id]
  (first (select #(= (:id %) id) policies)))

(defn get-field [map key table]
  (first (select #(= (:id %) (key map)) table)))

(defn get-holder [policy]
  (get-field policy :holder people))

(defn get-driver [vehicle]
  (get-field vehicle :driver people))

(defn get-vehicle [policy]
  (get-field policy :vehicle vehicles))

This feels very natural to use

(def p (find-policy 3))
(-> p get-vehicle get-driver)

I may consider using clj-record since it just uses macros to create
these kinds of functions for you.

Thanks again,
Brenton
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to