concept reduced in category clojure

appears as: reduced
Clojure: The Essential Reference

This is an excerpt from Manning's book Clojure: The Essential Reference.

The four functions in this section control the presence of a wrapping clojure.lang.Reduced marker object around other Clojure objects. The reduced signaling mechanism allows reducing functions to impose a premature end of the reduction:

(reduce
  (fn [acc el]          ; #1
    (if (> el 5)
      (reduced acc)     ; #2
      (+ acc el)))
  (range 10))

;; 15

When reduce finds an element wrapped in a Reduced instance, it stops recurring over the remaining elements in the input. Both reducers and transducers take advantage of the signaling mechanism to signal a premature end of the reduction (for example, take-while immediately wraps the results so far in a reduced so other reducers/transducers down the line have a chance to avoid computationally intensive operations).

The wrapped reduced instance supports the IDeref interface, allowing for easy inspection using the @ (at) operator: