Hi,

On 7 Okt., 08:29, Stefan Rohlfing <stefan.rohlf...@gmail.com> wrote:

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

Since no one mentioned reduce, here some variations. Your looping
construct with an accumulator which is simply returned should ring a
bell for reduce in your head.

(defn d-map
  [& kfps]
  (reduce (fn [res [k vs]] (reduce #(conj %1 [k %2]) res vs)) []
kfps))

(defn d-map
  [& kfps]
  (reduce (fn [res [k vs]] (reduce conj res (map vector (repeat k)
vs)) [] kfps)))

I would expect the first to be slightly faster. While the second might
be a little cleaner from an esoterical point of view.

Sincerely
Meikel

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