Skip to content

clojure.core/reductions

View this page on ClojureDocs

Type: function Added: Clojure 1.2 Examples: 4 Runnable: 2
([f coll] [f init coll])

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

Examples

by gstamp on
by Dimagog on . May have evaluation errors.
by pavanred on
by matrix10657 on . May have evaluation errors.

Note by betegelse

I think the description above would be clearer if it stated that the result of reductions is equivalent to the sequence of results of applying reduce to (take n coll), with n starting with 1, that is, equivalent to

(defn my-reduce [op coll] (for [n (range (count coll))] (reduce op (take (inc n) coll)))

Note by jayzawrotny

In other libraries and languages this function may be referred to as "scan".

See also


Content from the matching ClojureDocs page, with authors credited on each contribution.