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:
{"a...@gmail.com"
[{:email "a...@gmail.com", :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 <gvi...@gmail.com
<mailto:gvi...@gmail.com>> 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 "a...@gmail.com <mailto:a...@gmail.com>", :sign "Scorpio",
:planet "Mercury", :surname "Blogs", :first_name "Joe"}
{:email "a...@gmail.com <mailto:a...@gmail.com>", :sign "Leo", :planet
"Moon", :surname "Blogs", :first_name "Joe"}
{:email "a...@gmail.com <mailto:a...@gmail.com>", :sign "Scorpio",
:planet "Venus", :surname "Blogs", :first_name "Joe"}
{:email "a...@gmail.com <mailto:a...@gmail.com>", :sign "Cancer",
:planet "Mars", :surname "Blogs", :first_name "Joe"}
{:email "a...@gmail.com <mailto:a...@gmail.com>", :sign "Libra",
:planet "Sun", :surname "Blogs", :first_name "Joe"}
{:email "d...@gmail.com <mailto:d...@gmail.com>", :sign "Scorpio",
:planet "Mars", :surname "Doe", :first_name "Jane"}
{:email "d...@gmail.com <mailto:d...@gmail.com>", :sign "Taurus",
:planet "Moon", :surname "Doe", :first_name "Jane"}
{:email "d...@gmail.com <mailto:d...@gmail.com>", :sign "Cancer",
:planet "Mercury", :surname "Doe", :first_name "Jane"}
{:email "d...@gmail.com <mailto:d...@gmail.com>", :sign "Virgo",
:planet "Venus", :surname "Doe", :first_name "Jane"}
{:email "d...@gmail.com <mailto:d...@gmail.com>", :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 "a...@gmail.com <mailto:a...@gmail.com>" :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 clojure@googlegroups.com
<mailto: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
<mailto:clojure%2bunsubscr...@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 unsubscribe from this group and stop receiving emails from it,
send an email to clojure+unsubscr...@googlegroups.com
<mailto:clojure%2bunsubscr...@googlegroups.com>.
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 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 unsubscribe from this group and stop receiving emails from it, send
an email to clojure+unsubscr...@googlegroups.com
<mailto:clojure+unsubscr...@googlegroups.com>.
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 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 unsubscribe from this group and stop receiving emails from it, send an email
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.