In the comments to an answer of another question, I proposed the following Java code as a better way of writing a more procedural-style variant of the same operation:
employeeService.getEmployee()
.map(Employee::getId)
.ifPresent(System.out::println);
(where getEmployee()
returns an Optional<Employee>
)
An upvoted response to this comment suggests that this "drastically reduces code readability" and that the commentor would reject it in code review.
I don't understand this position: to me the code seems as readable, or even more readable, than the alternative procedural style code it was intended to replace. And yet at least two viewers of that comment believe it to be hard to read. Why is that? What makes this code difficult to read (at least for some readers)?