cgrand / xforms

Extra transducers and reducing fns for Clojure(script)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bug or question: multiplex -> partition -> unpredictable/unordered output?

lnostdal opened this issue · comments

> (dotimes [i 5]
    (println (sequence (comp (xforms/multiplex [(map inc)
                                                (map dec)])
                             (xforms/partition 2)
                             (map (fn [[^long a ^long b]] (- a b))))
                       (range 0 10))))

(2 2 2 2 2 2 2 2 2 2)
(-2 -2 -2 -2 -2 -2 -2 -2 -2 -2)
(-2 -2 -2 -2 -2 -2 -2 -2 -2 -2)
(-2 -2 -2 -2 -2 -2 -2 -2 -2 -2)
(2 2 2 2 2 2 2 2 2 2)

...shouldn't this give the same output on every run?

multiplex is not mapcat.
Each multiplexed transducer may have it's own rhythm (eg output 0, 1 or many items when processing one input item), there's no guarantee on the ordering of emitted values between transducers.