A side effect is an observable change beyond a computation’s direct return value. Writing files, updating databases, sending network requests, changing global state, and printing logs all alter the surrounding world. section 6.1.1
Side effects make behavior harder to trust when they remain hidden:
- Identical calls can produce different results when external factors or mutable state change. section 6.1.1
- Hidden mutations complicate reasoning, debugging, and testing because a method signature may not reveal what it changes. section 6.1.1
- Functional purity limits such effects by isolating behavior and expressing predictable transformations over data. section 6.0
Imperative steps versus a visible transformation
Imperative filtering creates a mutable result, loops through words, checks each condition, converts matches, and appends them. A functional pipeline makes the transformation itself visible: extract titles, sort them, then collect the result. section 6.1.1 section 6.0
List<String> result = new ArrayList<>();
for (String word : words) {
if (word.length() > 3) {
result.add(word.toUpperCase());
}
}
Inspect the imperative example’s explicit mutation and control flow. section 6.1.1
List<String> titles = books.stream() .map(Book::title) .sorted() .toList();
Inspect a concise pipeline that exposes data transformation without control-flow noise. section 6.0























