<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Clojure Q&amp;A - Recent questions tagged lazy chunking</title>
<link>https://ask.clojure.org/index.php/tag/lazy%20chunking</link>
<description>Powered by Question2Answer</description>
<item>
<title>Use transducers on clojure.core lazy sequence transformations</title>
<link>https://ask.clojure.org/index.php/12847/use-transducers-clojure-core-lazy-sequence-transformations</link>
<description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I heard that if transducers were included before in the language, they would have been used as the building blocks of all sequence lazy operations. Since they were added later, you need to adapt your code a bit to use transducers. And I was wondering why using &lt;code&gt;eduction&lt;/code&gt; is not an option? I&#039;m trying to understand the scenarios in which it&#039;s not a performance advantage to define the sequence lazy operations like this (of course assuming the same behaviour):&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(defn map
  ([f] ;; the standard transducer definition
   ,,,)
  ([f coll]
   (eduction (map f) coll))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I&#039;m trying to understand given the assumption (which might be an erroneous assumption) that&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(-&amp;gt;&amp;gt; (range 5000000)
     (eduction (map inc))
     (eduction (filter odd?))
     (eduction (map dec))
     (eduction (filter even?))
     (eduction (map (fn [n] (+ 3 n))))
     (eduction (filter odd?))
     (eduction (map inc))
     (eduction (filter odd?))
     (eduction (map dec))
     (eduction (filter even?))
     (eduction (map (fn [n] (+ 3 n))))
     (eduction (filter odd?))
     (into []))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;is the same as&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(-&amp;gt;&amp;gt; (range 5000000)
     (map inc)
     (filter odd?)
     (map dec)
     (filter even?)
     (map (fn [n] (+ 3 n)))
     (filter odd?)
     (map inc)
     (filter odd?)
     (map dec)
     (filter even?)
     (map (fn [n] (+ 3 n)))
     (filter odd?)
     (into []))
&lt;/code&gt;&lt;/pre&gt;
</description>
<category>Sequences</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/12847/use-transducers-clojure-core-lazy-sequence-transformations</guid>
<pubDate>Tue, 11 Apr 2023 06:55:00 +0000</pubDate>
</item>
<item>
<title>Is lazy sequence chunking deterministic?</title>
<link>https://ask.clojure.org/index.php/11687/is-lazy-sequence-chunking-deterministic</link>
<description>&lt;p&gt;I know that lazy sequences can be processed in a chunked manner.  That is, it may be that if my program needs &lt;em&gt;n&lt;/em&gt; elements from a lazy sequence, more than &lt;em&gt;n&lt;/em&gt; might be realized.&lt;/p&gt;
&lt;p&gt;Can I assume that if I run the same code a second time in the same version of Clojure, that exactly the same elements will get realized?  I would think so, but I don&#039;t want to assume that  without knowing.&lt;/p&gt;
&lt;p&gt;(I&#039;m including additional info here in case anyone is interested in why this matters, but I don&#039;t think it&#039;s necessary to know my use case in order to answer the question.  So &lt;strong&gt;feel free to skip this paragraph&lt;/strong&gt;. I&#039;m running simulations that make use of a pseudorandom number generator.  These involve random walks that are truncated if the walk encounters a &quot;target&quot;.  It&#039;s convenient to generate a walk in advance as a lazy sequence, and then stop realizing its elements when a target is found.  Normally, I throw away intermediate results such as the original random walk. They exist in a data structure at one time, but then I don&#039;t use them in the end.   However, I want to be able to go back and rerun a simulation, sometimes, in order to examine the intermediate results.  It&#039;s easy enough to store the seed that I used for a simulation run, and use it to set the random number generator to start in the same state.  However, chunking can cause the random number generator to be called more times than are strictly necessary.  That&#039;s OK, but if chunking can vary depending on something other than my code and the Clojure version, that could mean that rerunning a simulation with the same seed would not be guaranteed to produce the same results.  This is not at present a big deal.  I can make the intermediate data non-lazy without much of a performance hit.  However, I&#039;m still wondering whether that&#039;s necessary.)&lt;/p&gt;
</description>
<category>Collections</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/11687/is-lazy-sequence-chunking-deterministic</guid>
<pubDate>Mon, 28 Mar 2022 16:11:27 +0000</pubDate>
</item>
</channel>
</rss>