Try something like this:

(defn dmap [& args]
  (for [[head items] args]
        item in items]
    [head item]))

-Per

On Thu, Oct 7, 2010 at 1:29 PM, Stefan Rohlfing
<stefan.rohlf...@gmail.com> wrote:
> Dear Clojure Group,
>
> Following an Enlive tutorial I wanted to implement a function 'd-map'
> that takes an arbitrary number of [:key (list of values)] parameters
> like this:
>
> (d-map [:headline ["this" "is" "me"] ]
>            [:points [1 2 3] ]
>            [:comments [10 20 30] ])
>
>
> and returns a collection of [:key value] vectors where each value is
> grouped with its respective key:
>
> [ [:headline "this"] [:headline "is"] [:headline "me"]
>  [:points 1] [:points 2] [:points 3]
>  [:comments 10] [:comments 20] [:comments 30] ]
>
>
> I could only come up with the following implementation for 'd-map'.
> Although it works it just does not 'feel' elegant of even very
> functional:
>
> (defn d-map [& kfps]
>  (let [keys     (map first kfps)
>         fns       (map second kfps)]
>    (loop [keys keys fns fns res []]
>      (if (seq keys)
>        (recur (rest keys) (rest fns)
>                   (into res (map (fn [x] [(first keys) x]) (first
> fns))))
>        res))))
>
> I am relatively new to Clojure and want to learn how to write
> idiomatic code. I therefore appreciate any alternative implementation
> that might help me learn some new things.
>
> Stefan
>
> --
> 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 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