posted 3 years ago
On page 897 of the study guide, the following sentence is made: “The problem is that our lambda expression is stateful and modifies a list that is outside our stream.” Am I the only one who thinks that this sentence should, instead, be replaced by the following sentence: “The problem is that our lambda expression is stateful and modifies a list that is outside our stream pipeline”? This question is itself premised upon the following question: Does the list exist in the stream or in the stream pipeline?
Furthermore, this sentence states only one, albeit the basic, aspect of the problem for which a stateful operation is applied to the stream in this particular case. I believe that, in order for a statement of this problem to be complete, it needs to mention both of the following points:
(1.) The lambda expression is stateful because it modifies a list that is outside, not just the stream pipeline that is applied to the stream, but also outside the body of the lambda expression that is coded inside this pipeline that is applied to the stream. Would the lambda expression not also be stateful if it modified some state (variable) that is outside the body of the lambda expression, even though the variable state is inside the stream pipeline?
(2.) The lambda expression is stateful because code outside the lambda expression body could cause the stream, to which the pipeline (in which the lambda expression is coded) is applied, to be either a serial or a parallel stream. I know, someone may say, "but, at least, the book provides this as part the explanation for why the lambda expression is stateful, even if it only does that at one or more locations other than in this particular sentence in question." And, guess what? I will indeed agree with this factual observation and remark that someone could make. However, my point here is not to argue that the book does not provide this robust/complete explanation at all; rather, my point is to observe and remark that this robust/complete explanation is not included in this sentence, which (summarily) states the explanation for why the lambda expression is stateful.