The benchmark is wrong atm, the compared functions do not yield the same result.
(comp (map inc) (filter even?)) means filtering first, then incrementing.
The opposite for (->> data (map inc) (filter even?) ...
- which is not the same. And of course, it also means that the latter has to increment the double amount of numbers.
EDIT: It was me who was wrong, thanks for the corrections. Pitfall successfully identified :)
Nope, that's the funny feature of transducers. Like lenses in Haskell, transducers compose in reversed order.
(sequence (comp (map inc) (filter even?)) (range 10))
;;=> (2 4 6 8 10)
(->> (range 10) (map inc) (filter even?))
;;=> (2 4 6 8 10)
Both test functions in transduce-bench return 250000500000.
Re:Transducers are coming to Clojure
by richhickey on Thursday August 07, 2014 @07:38AM
(#8147148)
It seems counterintuitive, but composing transducers yields a reducing function that runs the transformation steps left->right. What you are composing is the reducing function transformations (right to left, ordinary composition), but their result, having been built inside-out, runs the steps outside-in. So (comp tx1 tx2...) runs in same order as (->> xs tx1 tx2...)
Add salt according to taste.