I have defined these types of records for modelling a simple shopping cart:

; An item in the cart
(defrecord Item [id name product quantity purchased])

; The product that relates to the item in the cart
(defrecord Product [id name description prices])

; A price definition
(defrecord Price [price tax-rate currency])


; Sample items
(def items [
             (->Item 1 "Brogues" "P-123" 1 true)
             (->Item 2 "Underpants" "P-345" 1 false)
             (->Item 3 "Shirt" "P-678" 1 true)
             ])

; Sample products
(def products [
                (->Product "P-123" "Brogues" "Men's Leather Slip on 
Brogues" (->Price 93.00 21 "EURO"))
                (->Product "P-345" "Underpants" "CK Y Fronts" (->Price 
23.50 21 "EURO"))
                (->Product "P-678" "Shirt" "Slim Fit White Vest Shirt" 
(->Price 45.99 21 "EURO"))
                (->Product "P-1231" "Table" "Coffee Table" (->Price 375 21 
"EURO"))
                (->Product "P-3451" "Chairs" "Set of Four(4) chairs" 
(->Price 200 21 "EURO"))
                (->Product "P-6781" "TableCloth" "Classic red and white 
checks 2m x 2m" (->Price 17.99 21 "EURO"))
                ])

My requirement is to combine data from the two collections such that I can 
show the detailed product information for any item, for example:

             (->Item 3 "Shirt" "Slim Fit White Vest Shirt" (->Price 45.99 
21 "EURO") 1 true)

When I tried to use merge-with union I had an error which surprised me 
since I thought records are also maps:

user=> (merge-with union items products)
ClassCastException user.Product cannot be cast to java.util.Map$Entry 
 clojure.core/key (core.clj:1465)

Although I will fight on, any tips from any of you that have done this 
before would be greatly helped.

Thanks

ray

-- 
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