• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Sybex CSG 11: Summary Explanation, for why Lambda Expression is Stateful, can be Made More Robust

 
Ranch Hand
Posts: 118
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Nyeng Gyang
Ranch Hand
Posts: 118
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My suggestion, for how the sentence in question could be made robust/complete, is as follows: “The problem is that our lambda expression is stateful and modifies a list that is outside our stream pipeline, so that the result of executing the lambda, when the pipeline is executed, depends on whether the stream is a serial or a parallel stream.”
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic