reductions

functionsince v0.0-927 clojure.core/reductionsEdit
(reductions f coll)
(reductions f init coll)

Details:

Returns a lazy sequence of the intermediate values of the reduction (as per reduce) of coll by f, starting with init.


See Also:


Source docstring:
Returns a lazy seq of the intermediate values of the reduction (as
per reduce) of coll by f, starting with init.
Source code @ clojurescript:src/main/cljs/cljs/core.cljs
(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))))))))