x/count can now be used as a transducing context (x/count xform coll). /cc @iig
This commit is contained in:
parent
62c3dd15cc
commit
d16bd380fa
1 changed files with 11 additions and 6 deletions
|
|
@ -433,12 +433,17 @@
|
||||||
(vswap! vwacc f x))
|
(vswap! vwacc f x))
|
||||||
acc))))))))
|
acc))))))))
|
||||||
|
|
||||||
(defn count [rf]
|
(defn count
|
||||||
(let [n (java.util.concurrent.atomic.AtomicLong.)]
|
"Count the number of items. Either used directly as a transducer or invoked with two args
|
||||||
(fn
|
as a transducing context."
|
||||||
([] (rf))
|
([rf]
|
||||||
([acc] (rf (unreduced (rf acc (.get n)))))
|
(let [n (java.util.concurrent.atomic.AtomicLong.)]
|
||||||
([acc _] (.incrementAndGet n) acc))))
|
(fn
|
||||||
|
([] (rf))
|
||||||
|
([acc] (rf (unreduced (rf acc (.get n)))))
|
||||||
|
([acc _] (.incrementAndGet n) acc))))
|
||||||
|
([xform coll]
|
||||||
|
(transduce (comp xform count) rf/last coll)))
|
||||||
|
|
||||||
(defn multiplex
|
(defn multiplex
|
||||||
"Returns a transducer that runs several transducers (sepcified by xforms) in parallel.
|
"Returns a transducer that runs several transducers (sepcified by xforms) in parallel.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue