I'm new to clojure. I've return an utility function to filter a sequence of
map by some key but it's not working. Here is the sample code -
(def data [{:id 1 :b 2}
{:id 3 :b 4}
{:id 5 :b 6}
{:id 7 :b 8}])
In real app this is a sequence of maps read from csv file.
(defn get-data
[& attrs]
(let [grps data]
(if (empty? attrs)
grps
(map #(select-keys % attrs) grps))))
(filter #(= (% :id) 7) (get-data :id :b))
Why above expression works but same expression wrapped as function (below)
does not work?
(defn get-data-by-id [id & attrs]
"always pass :id attribute"
(filter #(= (:id %) id) (get-data attrs)))
(get-data-by-id 3) ;; returns () this is probably ok (?) since :id key is
not available
(get-data-by-id 3 :id :b) ;; returns () but why this does not work?
Pleas help me to figure this out.
thanks & cheers!
-tilak
--
--
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
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.