Perhaps something like:
(defn planet-sign-map [signs]
(into {} (map (juxt :planet :sign) signs)))
(defn extract-planet-signs [signs]
(for [[email signs] (group-by :email signs)]
{:email email, :signs (planet-sign-map signs)}))
(defn find-planet-signs [emails]
(extract-planet-signs (get-signs {:em emails})))
- James
On 5 June 2015 at 17:24, gvim <[email protected]> wrote:
> I have a YeSQL query:
>
> (get-signs {:em emails}) ;; emails is a vector of email address strings
>
> ... which produces this list of maps:
>
> (
> {:email "[email protected]", :sign "Scorpio", :planet "Mercury", :surname
> "Blogs", :first_name "Joe"}
> {:email "[email protected]", :sign "Leo", :planet "Moon", :surname "Blogs",
> :first_name "Joe"}
> {:email "[email protected]", :sign "Scorpio", :planet "Venus", :surname
> "Blogs", :first_name "Joe"}
> {:email "[email protected]", :sign "Cancer", :planet "Mars", :surname
> "Blogs", :first_name "Joe"}
> {:email "[email protected]", :sign "Libra", :planet "Sun", :surname "Blogs",
> :first_name "Joe"}
>
> {:email "[email protected]", :sign "Scorpio", :planet "Mars", :surname "Doe",
> :first_name "Jane"}
> {:email "[email protected]", :sign "Taurus", :planet "Moon", :surname "Doe",
> :first_name "Jane"}
> {:email "[email protected]", :sign "Cancer", :planet "Mercury", :surname
> "Doe", :first_name "Jane"}
> {:email "[email protected]", :sign "Virgo", :planet "Venus", :surname "Doe",
> :first_name "Jane"}
> {:email "[email protected]", :sign "Leo", :planet "Sun", :surname "Doe",
> :first_name "Jane"}
> )
>
> I want to transform this data structure into a list of maps in this format:
>
> {:email "[email protected]" :planet-signs {:Sun "Libra" :Moon "Leo" :Mercury
> "Scorpio" :Venus "Scorpio" :Mars "Cancer"]}
>
> I started with:
>
> (defn extract-planet-signs [emails]
> (let [results (group-by :email (get-signs {:em emails}))]
> (for [email-key (keys results)
> {:keys [email sign planet surname first_name]} (results
> email-key)
>
> ... but beyond that I'm a bit stuck. Any ideas?
>
> gvim
>
>
>
> --
> 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.
>
--
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.