see also this page:
http://clojure.org/sequences
where for is listed among the seq library functions
HTH
Gianluca
--
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
On 06/06/2015 05:01, Sean Corfield wrote:
Page 84 is where it shows that maps are a sequence of pairs.
The destructuring in James's code is on vectors -- the pairs in the
sequence.
Hope that helps?
Sean
Page 84 describes the sequence abstraction in general but it's the
implicit seq in for
x and y are destructured into the key and value of each map entry. Z is
nil.
The second example uses seq to convert the map into a sequence of map
entries and then it destructures the seq (not the map entries themselves).
The third example does destructure the map entries.
(let [[a b c] [1 2]]
(for [[x y z] {:a aa :b bb :c cc}] [x y z])
([:c cc nil] [:b bb nil] [:a aa nil]);; WTF?
So her, I guess, your taking each entry in the map and destructuring them into
the three vars x, y, and z. Since each map entry is a pair, the third var z
will be nil.
Erik.
--
i farta
Den 6.
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, :sign Scorpio, :planet Mercury, :surname
Blogs, :first_name Joe}
{:email a...@gmail.com, :sign Leo, :planet Moon, :surname Blogs,
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
I must re-read Clojure Programming (O'Reilly) in that case as I don't
recall the authors mentioning this kind of destructuring.
gvim
On 06/06/2015 03:33, Fluid Dynamics wrote:
On Friday, June 5, 2015 at 10:07:05 PM UTC-4, g vim wrote:
That works but I missed this possibility because I'm
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
On Friday, June 5, 2015 at 10:07:05 PM UTC-4, g vim wrote:
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 javascript:
[{:email a...@gmail.com javascript:, :sign Cancer,
Yes, I'm fine with the concept. Just can't remember coming across it in
the textbooks but maybe I wasn't paying attention :)
gvim
On 06/06/2015 04:08, Sean Corfield wrote:
It’s because if you treat a hash map as a sequence — as `for` does — you get a
sequence of pairs (key/value — map
Page 84 is where it shows that maps are a sequence of pairs.
The destructuring in James's code is on vectors -- the pairs in the
sequence.
Hope that helps?
Sean
On Fri, Jun 5, 2015 at 8:11 PM, gvim gvi...@gmail.com wrote:
Yes, I'm fine with the concept. Just can't remember coming across it
It’s because if you treat a hash map as a sequence — as `for` does — you get a
sequence of pairs (key/value — map entries):
(seq {:a 1 :b 2})
;;= ([:a 1] [:b 2])
Does that help?
Sean
On Jun 5, 2015, at 7:41 PM, gvim gvi...@gmail.com wrote:
I must re-read Clojure
12 matches
Mail list logo