cgrand / xforms

Extra transducers and reducing fns for Clojure(script)
573 stars 32 forks source link

Incorrect behavior of combination of partition and reduce #14

Closed coder11 closed 7 years ago

coder11 commented 7 years ago

When you use partition to group input seq into batches, then map to do some processing and finally reduce to aggregate result, transduce behavior is incorrect. It returns empty vector instead when batch size is divisible of seq count.

(transduce
 (comp
  (x/partition 2 2 nil)
  (map count)
  (x/reduce +))
 conj
 (range 4)) => []

However, without reduce result is correct:

(transduce
 (comp
  (x/partition 2 2 nil)
  (map count))
 conj
 (range 4)) => [2 2]

Also, if batch does not divide evenly, everything works fine:

(transduce
 (comp
  (x/partition 2 2 nil)
  (map count)
  (x/reduce +))
 conj
(range 5)) => [5]

version 0.9.2

cgrand commented 7 years ago

Good catch, there's a missing call to rf on this line https://github.com/cgrand/xforms/blob/master/src/net/cgrand/xforms.cljc#L333

cgrand commented 7 years ago

Published 0.9.3 which includes the fix. Thanks for the report!