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 <[email protected]> wrote:
>
> 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 still not clear
>> how:
>>
>> (group-by :email signs)
>>
>> .... which produces a map of the form:
>>
>> {"[email protected] <javascript:>"
>> [{:email "[email protected] <javascript:>", :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.
>>
>>
>> The code was (for [[email signs] (group-by...)]...). The for iterates
>> over the map produced by group-by, producing individual map entries, and
>> map entries can be treated as two-element seqs/vectors of [key value],
>> which is what the destructuring does here, putting the key in local
>> binding email and the value, a vector with maps in it, in signs.
--
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.