Problem Statement
Why are side effects inside Stream intermediate operations discouraged, and what should you use instead?
Explanation
Side effects (e.g., mutating external state in map/filter) break referential transparency, hinder parallelization, and cause subtle bugs. Prefer pure functions and let `collect` build results. If you must observe, use `peek` only for diagnostics; for imperative accumulation, a simple loop may be clearer.
Practice Sets
This question appears in the following practice sets:
