On Sun, Dec 9, 2012 at 4:45 PM, mond <r...@mcdermott.be> wrote:

> ; I have these records defined
>
> (defrecord Customer [firstName lastName emailAddress deliveryAddress
> invoiceAddress])
> (defrecord Address [street number town postcode])
>

This looks fine


>
> ; I have this small sample data
> (def customers
>   {
>     (->Customer "Drongo" "Bongo" "dro...@bongo.co"
>       (->Address "Gongo" "32A" "Fongo" 8888)
>       (->Address "Gongo" "32B" "Fongo" 1111))
>
>       (->Customer "Tinga" "Zinga" "qi...@zinga.co"
>         (->Address "Thinga" "767" "Dongo" 2222)
>         (->Address "Jinga" "828" "Qongo" 3333))
>     }
> )
>

You probably want this to be a vector of customers instead of a map?

so,

(def customers
 [
  (->Customer "Drongo" "Bongo" "dro...@bongo.co"
   (->Address "Gongo" "32A" "Fongo" 8888)
   (->Address "Gongo" "32B" "Fongo" 1111))

   (->Customer "Tinga" "Zinga" "qi...@zinga.co"
    (->Address "Thinga" "767" "Dongo" 2222)
    (->Address "Jinga" "828" "Qongo" 3333))
  ]
)


>
> ; and I want a small filter on an embedded property
> (deliveryAddress.number)
> ; this compiles but of course it's wrong so gives back an empty list
>
> (prn (filter #(= "32A" (:deliveryAddress :number %)) customers))
>

So you can write this a bunch of different ways:

(prn (filter #(= (:number (:deliveryAddress %)) "32A") customers))

or if you want to use ->, you can:

(prn (filter #(-> % :deliveryAddress :number (= "32A")) customers))

Cheers,

Jordan

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