<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Clojure Q&amp;A - Recent questions tagged sequence</title>
<link>https://ask.clojure.org/index.php/tag/sequence</link>
<description></description>
<item>
<title>Infinite lazy sequence expands until JVM runs out of memory</title>
<link>https://ask.clojure.org/index.php/13111/infinite-lazy-sequence-expands-until-jvm-runs-out-of-memory</link>
<description>&lt;p&gt;Hello, I am new to Clojure and to lazy sequences.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(defn get-biggest-prime-factor [num]
  (let [max-check (inc (Math/sqrt num))
        lazy-primes (filter-lazy-seq is_prime naturals)]
    (loop [prime (first lazy-primes)
           max-factor 1]
      (cond (&amp;gt;= prime max-check) max-factor
            (= 0 (rem num prime)) (recur (first (rest lazy-primes)) (first lazy-primes))
            :else (recur (first (rest lazy-primes)) max-factor)))) )
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;naturals&lt;/strong&gt; is an infinite lazy sequence of 1,2,3 ... ,&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;filter-lazy-seq&lt;/strong&gt; is a function, which returns a lazy sequence derived from second argument. Every element of sequence is verified by first argument, which is a predicate&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;is-prime&lt;/strong&gt; is a function that check if a number is prime&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Any help is appreciated.&lt;/p&gt;
</description>
<category>Sequences</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/13111/infinite-lazy-sequence-expands-until-jvm-runs-out-of-memory</guid>
<pubDate>Sat, 29 Jul 2023 23:20:23 +0000</pubDate>
</item>
<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'm trying to understand the scenarios in which it'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'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>Allow `keep` to accept multiple collections (a la map)</title>
<link>https://ask.clojure.org/index.php/12755/allow-keep-to-accept-multiple-collections-a-la-map</link>
<description>&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://ask.clojure.org/index.php/3345/allow-map-indexed-to-accept-multiple-collections-a-la-map&quot;&gt;https://ask.clojure.org/index.php/3345/allow-map-indexed-to-accept-multiple-collections-a-la-map&lt;/a&gt; comments here indicated this should be its own jira.  I couldn't see that a jira had actually been created though.&lt;/p&gt;
</description>
<category>Clojure</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/12755/allow-keep-to-accept-multiple-collections-a-la-map</guid>
<pubDate>Mon, 13 Mar 2023 14:50:07 +0000</pubDate>
</item>
<item>
<title>Why does '=' return false for these two sequences?</title>
<link>https://ask.clojure.org/index.php/10206/why-does-return-false-for-these-two-sequences</link>
<description>&lt;p&gt;I have two sequences 'a' and 'b'. Both have the same length and their corresponding element compare equal with '='. But if these two sequences are passed to '=', the result is false:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(doseq [[x y] (zip-colls a b)]
  (println (= x y)))
true
true
true
true

(count a)
4
(count b)
4

(= a b)
false
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is in contradiction with the clojure equality rule:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;Clojure’s = is true when called with two collections, if:&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;&lt;p&gt;Both arguments are sequential (sequences, lists, vectors, queues, or Java collections implementing java.util.List) with = elements in the same order.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I'm comparing two instances of this class: &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/fctorial/parse_struct/blob/master/src/clojure/lang/ROVec.java&quot;&gt;https://github.com/fctorial/parse_struct/blob/master/src/clojure/lang/ROVec.java&lt;/a&gt;&lt;/p&gt;
</description>
<category>Clojure</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/10206/why-does-return-false-for-these-two-sequences</guid>
<pubDate>Thu, 18 Feb 2021 07:06:07 +0000</pubDate>
</item>
<item>
<title>Suspected bug in `clojure.core/partition`</title>
<link>https://ask.clojure.org/index.php/9937/suspected-bug-in-clojure-core-partition</link>
<description>&lt;p&gt;2 problems:&lt;br&gt;
- The docstring of clojure.core/partition is not clear on what &quot;last partition&quot; means.&lt;br&gt;
- The behavior of partition is strange, IHMO it has a bug.&lt;/p&gt;
&lt;p&gt;Please take a look at this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(partition 3 1 [:a :b :c] (range 5))

; actual behavior
; =&amp;gt; ((0 1 2) (1 2 3) (2 3 4) (3 4 :a))

; expected behavior, option 1
; =&amp;gt; ((0 1 2) (1 2 3) (2 3 4))

; expected behavior, option 2
; =&amp;gt; ((0 1 2) (1 2 3) (2 3 4) (3 4 :a) (4 :a :b))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I would expect the &quot;last partition&quot; to be defined as:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;The last partition to contain elements from the input collection (not the padding collection) which are not present in any previous partition.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This is consistent with option 1 above.&lt;/p&gt;
</description>
<category>Sequences</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/9937/suspected-bug-in-clojure-core-partition</guid>
<pubDate>Thu, 10 Dec 2020 02:54:45 +0000</pubDate>
</item>
</channel>
</rss>