| function | since v0.0-927 | Edit |
(reductions f coll)(reductions f init coll)Returns a lazy sequence of the intermediate values of the reduction (as per
reduce) of coll by f, starting with init.
Returns a lazy seq of the intermediate values of the reduction (as per reduce) of coll by f, starting with init.
(defn reductions
([f coll]
(lazy-seq
(if-let [s (seq coll)]
(reductions f (first s) (rest s))
(list (f)))))
([f init coll]
(if (reduced? init)
(list @init)
(cons init
(lazy-seq
(when-let [s (seq coll)]
(reductions f (f init (first s)) (rest s))))))))