That works but I missed this possibility because I'm still not clear how:
(group-by :email signs)
.... which produces a map of the form:
{"[email protected]"
[{:email "[email protected]", :sign "Cancer", :planet "Mars", :surname
"Blogs", :first_name "Joe"}
..... ]}
.... can be destructured with the vector [email signs]. I assumed a map
must be destructured with a map but couldn't find a solution as the map
keys are unique values, ie. email addresses.
I reduced your solution to:
(defn extract-planet-signs [emails]
(for [[email signs] (group-by :email (get-signs {:em emails}))]
{:email email, :signs (into {} (map (juxt :planet :sign) signs))}))
Thanks
gvim
On 05/06/2015 21:26, James Reeves wrote:
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]
<mailto:[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] <mailto:[email protected]>", :sign "Scorpio",
:planet "Mercury", :surname "Blogs", :first_name "Joe"}
{:email "[email protected] <mailto:[email protected]>", :sign "Leo", :planet
"Moon", :surname "Blogs", :first_name "Joe"}
{:email "[email protected] <mailto:[email protected]>", :sign "Scorpio",
:planet "Venus", :surname "Blogs", :first_name "Joe"}
{:email "[email protected] <mailto:[email protected]>", :sign "Cancer",
:planet "Mars", :surname "Blogs", :first_name "Joe"}
{:email "[email protected] <mailto:[email protected]>", :sign "Libra",
:planet "Sun", :surname "Blogs", :first_name "Joe"}
{:email "[email protected] <mailto:[email protected]>", :sign "Scorpio",
:planet "Mars", :surname "Doe", :first_name "Jane"}
{:email "[email protected] <mailto:[email protected]>", :sign "Taurus",
:planet "Moon", :surname "Doe", :first_name "Jane"}
{:email "[email protected] <mailto:[email protected]>", :sign "Cancer",
:planet "Mercury", :surname "Doe", :first_name "Jane"}
{:email "[email protected] <mailto:[email protected]>", :sign "Virgo",
:planet "Venus", :surname "Doe", :first_name "Jane"}
{:email "[email protected] <mailto:[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] <mailto:[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]
<mailto:[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]
<mailto:clojure%[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]
<mailto:clojure%[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]
<mailto:[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.