That doesn't mean that we're not walking the seq twice, however. keys and
vals work off of separate calls to seq on the map, which of necessity
produce distinct seq objects (otherwise traversing a seq over a map would
permanently increase its memory consumption).


On 2 February 2014 05:18, Michał Marczyk <[email protected]> wrote:

> On 2 February 2014 05:14, Justin Smith <[email protected]> wrote:
>
>> Pardon my ignorance but if this is producing a lazy result, how is it
>> doing so?
>>
>> https://github.com/clojure/clojure/blob/dff9600387b962f16fc78e6477e10e34651fd366/src/jvm/clojure/lang/APersistentMap.java#L134
>>
>
> APersistentMap's KeySeq.create and ValSeq.create are pretty much
> equivalent to (map key entry-seq) and (map val entry-seq). The logic
> producing entry-seq lives in the individual map types and is indeed lazy.
>
> Cheers,
> Michał
>
>
>>
>> On Saturday, February 1, 2014 7:54:32 PM UTC-8, Ambrose Bonnaire-Sergeant
>> wrote:
>>
>>> zipmap could also potentially use transients (which would be a nice
>>> addition).
>>>
>>> keys/vals are also lazy, so I would be surprised if there was any
>>> performance
>>> difference with walking the seq "twice".
>>>
>>> Thanks,
>>> Ambrose
>>>
>>>
>>> On Sun, Feb 2, 2014 at 11:35 AM, Justin Smith <[email protected]>wrote:
>>>
>>>> Realistically, how many situations are there where running keys and
>>>> vals independently is preferable to running seq once and using the two
>>>> element vectors that returns?
>>>>
>>>> Usually this way one can avoid walking the whole thing twice.
>>>>
>>>> (into {} (map (fn [[k v]] [k (inc v)]) {:a 0 :b 1})) is representative
>>>> of the idiom I usually use. As a bonus, into uses transients, which can
>>>> create the resulting structure in fewer cycles / less time.
>>>>
>>>>
>>>> On Saturday, February 1, 2014 10:00:33 AM UTC-8, Sam Ritchie wrote:
>>>>
>>>>> Looks like Rich just chimed in with:
>>>>>
>>>>> "keys order == vals order == seq order "
>>>>>
>>>>>   Matching Socks
>>>>>  January 31, 2014 7:31 PM
>>>>> Actually, http://dev.clojure.org/jira/browse/CLJ-1302 "keys and vals
>>>>> consistency not mentioned in docstring" was declined, with the comment 
>>>>> "The
>>>>> absence of this property in the docs is correct. You should not rely on
>>>>> this."
>>>>>
>>>>>
>>>>>
>>>>> On Wednesday, August 11, 2010 6:03:39 PM UTC-4, Chouser wrote:
>>>>> --
>>>>> 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/groups/opt_out.
>>>>>
>>>>>
>>>>> --
>>>>> Sam Ritchie (@sritchie)
>>>>>  Paddleguru Co-Founder
>>>>> 703.863.8561
>>>>> www.paddleguru.com
>>>>> Twitter <http://twitter.com/paddleguru> // 
>>>>> Facebook<http://facebook.com/paddleguru>
>>>>>
>>>>  --
>>>> 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/groups/opt_out.
>>>>
>>>
>>>  --
>> 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/groups/opt_out.
>>
>
>

-- 
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/groups/opt_out.

Reply via email to