diff --git a/README.md b/README.md index a0c7607..2804214 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Transducing contexts: `transjuxt` (for performing several transductions in a sin Add this dependency to your project: ```clj -[net.cgrand/xforms "0.8.2"] +[net.cgrand/xforms "0.8.3"] ``` ```clj @@ -127,16 +127,16 @@ It's worth noting that all transformed outputs are subsequently interleaved. See ```clj => (sequence (x/partition 2 1 identity) (range 8)) -(0 1 1 2 2 3 3 4 4 5 5 6 6 7 7) +(0 1 1 2 2 3 3 4 4 5 5 6 6 7) => (sequence (x/by-key odd? identity) (range 8)) ([false 0] [true 1] [false 2] [true 3] [false 4] [true 5] [false 6] [true 7]) ``` -That's why most of the time the last stage of the sub-transducer will be a `x/reduce` or a `x/into`: +That's why most of the time the last stage of the sub-transducer will be a 1-item transducer like `x/reduce` or `x/into`: ```clj => (sequence (x/partition 2 1 (x/into [])) (range 8)) -([0 1] [1 2] [2 3] [3 4] [4 5] [5 6] [6 7] [7]) +([0 1] [1 2] [2 3] [3 4] [4 5] [5 6] [6 7]) => (sequence (x/by-key odd? (x/into [])) (range 8)) ([false [0 2 4 6]] [true [1 3 5 7]]) ``` diff --git a/project.clj b/project.clj index d744def..90e9a49 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject net.cgrand/xforms "0.8.2" +(defproject net.cgrand/xforms "0.8.3" :description "Extra transducers for Clojure" :url "https://github.com/cgrand/xforms" :license {:name "Eclipse Public License" diff --git a/src/net/cgrand/xforms.cljc b/src/net/cgrand/xforms.cljc index 6028477..bd48345 100644 --- a/src/net/cgrand/xforms.cljc +++ b/src/net/cgrand/xforms.cljc @@ -321,7 +321,7 @@ (let [xform (comp cat (take n) xform) ; don't use mxrf for completion: we want completion and don't want reduced-wrapping acc (transduce xform rf acc [(.getValues dq) pad])] - (vreset! @barrier n) + (vreset! barrier n) (.clear dq) acc) acc)) @@ -330,8 +330,8 @@ (when (< b n) (.add dq (if (nil? x) dq x))) (if (zero? b) ; this transduce may return a reduced because of mxrf wrapping reduceds coming from rf - (let [acc (transduce xform mxrf acc (.getValues dq))] - (dotimes [_ (min n step)] (.poll dq)) + (let [acc (core/transduce xform mxrf acc (.getValues dq))] + (dotimes [_ (core/min n step)] (.poll dq)) (vswap! barrier + step) acc) acc))))))))) diff --git a/test/net/cgrand/xforms_test.cljc b/test/net/cgrand/xforms_test.cljc index 24b67cd..20c8657 100644 --- a/test/net/cgrand/xforms_test.cljc +++ b/test/net/cgrand/xforms_test.cljc @@ -82,6 +82,12 @@ (is (= (into [] (comp (take 3) (x/reductions +)) (range)) [0 0 1 3])) (is (= (into [] (x/reductions (constantly (reduced 42)) 0) (range)) [0 42]))) +(deftest partition + (is (= (into [] (x/partition 2 1 nil (x/into [])) (range 8)) + [[0 1] [1 2] [2 3] [3 4] [4 5] [5 6] [6 7] [7]])) + (is (= (into [] (x/partition 2 1 (x/into [])) (range 8)) + [[0 1] [1 2] [2 3] [3 4] [4 5] [5 6] [6 7]]))) + #?(:clj (deftest window-by-time (is (= (into