On Jun 8, 2014, at 3:12 PM, boz <[email protected]> wrote:
> Is there a better way to take this...
>
> [[:a [1 2]]
> [:b [3 4]]]
>
> and convert it to this...
>
> [[:a 1]
> [:a 2]
> [:b 3]
> [:b 4]]
>
> than using a loop like this...
>
> (defn doit [id v]
> (loop [a (first v) r (rest v) result []]
> (if a
> (recur (first r) (rest r) (conj result [id a]))
> result)))
>
> ???
Lots of possibilities, and your loop doesn't look to me like it's handling the
ids right, but FWIW I might do something like:
(defn split-key-pairs [grouped-data]
(vec (apply concat (for [[key vals] grouped-data]
(for [v vals] [key v])))))
=> (split-key-pairs [[:a [1 2]] [:b [3 4]]])
[[:a 1] [:a 2] [:b 3] [:b 4]]
-Lee
--
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/d/optout.