On 07.08.2013 10:58, Tilak Thapa wrote:
> (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?

`get-data-by-id` passes one argument to `get-data`: a sequence of
attributes. `get-data-by-id` expects one argument per attribute. Instead
of `(get-data attrs)`, use `(apply get-data attrs)`.

See http://clojuredocs.org/clojure_core/clojure.core/apply for examples
demonstrating the use of `apply`.

-- 
Timo

-- 
-- 
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
--- 
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 clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to