Fix issue with iterator

When there was only 1-item produced by an aggregating xform .hasNext was returning false.
This commit is contained in:
Christophe Grand 2017-10-19 11:38:19 -05:00
parent da53490f20
commit 023ca6043e
3 changed files with 14 additions and 8 deletions

View file

@ -1,4 +1,4 @@
(defproject net.cgrand/xforms "0.12.1"
(defproject net.cgrand/xforms "0.12.2"
:description "Extra transducers for Clojure"
:url "https://github.com/cgrand/xforms"
:license {:name "Eclipse Public License"

View file

@ -479,13 +479,17 @@
rf (xform (fn ([acc] acc) ([acc x] (.push dq (if (some? x) x NULL)) acc)))
vopen (volatile! true)
ensure-next #(or (some? (.peek dq))
(if (and @vopen (.hasNext src-iterator))
(let [acc (rf nil (.next src-iterator))]
(when (reduced? acc) (vreset! vopen false))
(recur))
(do
(rf nil)
false)))]
(and @vopen
(if (.hasNext src-iterator)
(let [acc (rf nil (.next src-iterator))]
(when (reduced? acc)
(rf nil)
(vreset! vopen false))
(recur))
(do
(rf nil)
(vreset! vopen false)
(recur)))))]
(reify java.util.Iterator
(hasNext [_]
(ensure-next))

View file

@ -92,6 +92,8 @@
#?(:clj
(deftest iterator
(is (true? (.hasNext (x/iterator x/count (.iterator (range 5))))))
(is (is (= [5] (iterator-seq (x/iterator x/count (.iterator (range 5)))))))
(is (= [[0 1] [1 2] [2 3] [3 4] [4]] (iterator-seq (x/iterator (x/partition 2 1 nil) (.iterator (range 5)))))))
(deftest window-by-time