title: Clojure: reduce, reductions and infinite lists
body: <p>Reduce and reductions let you accumulate state over a sequence.
  Each element in the sequence will modify the accumulated state until
  the end of the sequence is reached. </p>
  
  <p>What are implications of calling reduce or reductions on an infinite list?</p>
  
  <pre><code>(def c (cycle [0]))
  (reduce + c)
  </code></pre>
  
  <p>This will quickly throw an OutOfMemoryError. By the way, <code>(reduce + (cycle [0]))</code> does not throw an OutOfMemoryError (at least not for the time I waited). It never returns. Not sure why. </p>
  
  <p>Is there any way to call reduce or reductions on an infinite list in a way that makes sense?  The problem I see in the above example, is that eventually the evaluated part of the list becomes large enough to overflow the heap. Maybe an infinite list is not the right paradigm. Reducing over a generator, IO stream, or an event stream would make more sense. The value should not be kept after it's evaluated and used to modify the state.      </p>