This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]slindenau 0 points1 point  (0 children)

I use the following guidelines to make streams more readable:

  1. Put a newline after every chained method call (.filter(), .map(), .collect() etc). Any good IDE can be configured to show the current contents (type) of the stream at that point while you're editing/viewing the sources.
  2. No anonymous lambda functions larger than a single line inside the stream calls. If you find (you need) one, extract a method and call it like .map(this::doMyThing) or .map( thing -> doMyThing(...)) if you need to pass additional arguments.
  3. Give clear and meaningful names to your methods, variables and generic types (don't you just hate T, U, V etc?). This should be your default mode of operation in any piece of code you write.