On Sun, Dec 9, 2012 at 4:45 PM, mond <[email protected]> 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" "[email protected]"
> (->Address "Gongo" "32A" "Fongo" 8888)
> (->Address "Gongo" "32B" "Fongo" 1111))
>
> (->Customer "Tinga" "Zinga" "[email protected]"
> (->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" "[email protected]"
(->Address "Gongo" "32A" "Fongo" 8888)
(->Address "Gongo" "32B" "Fongo" 1111))
(->Customer "Tinga" "Zinga" "[email protected]"
(->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 [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en