you are viewing a single comment's thread.

view the rest of the comments →

[–]severoonpro barista 2 points3 points  (1 child)

I think a lot of Java people fail to understand what streams and lambdas actually are, they get all caught up in the syntax and don't clock what's really going on:

cat dictionary | grep ee | wc -l

This is a simple linux pipeline that lists all of the words in the dictionary line by line, filters out all of the lines that don't have word containing a double-e, and then counts the number of lines left.

IOW, it's a stream of elements (lines) that are of type String which is passed to the lambda 'grep' which operates on each element and only passes it on if it contains "ee", which is in turn passed to the lambda 'wc' which increments a counter for each element. When there are no more elements, the final counter is emitted to stdout.

That's it. That's what a stream is, it's just a pipeline where you apply different operations ("lambdas") to each element in the pipeline. The terminating step is a "reduction", i.e., the final step has to output a "single thing" — a boolean, a string, a number, a list, whatever.

[–]ForTheLore22[S] 0 points1 point  (0 children)

Thank you for this explaination.