-
-
Notifications
You must be signed in to change notification settings - Fork 737
Add new Streams concept with intro and resources #3041
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for wanting to contribute the Streams concept, but there is already an open PR for this (#2983) so I'm going to put this one on hold by putting this in "requested changes" state. Admittedly, the other one hasn't had activity for a while, so I've pinged the other PR's author on that one. If there's no reply or if they've lost interest, I'll come back to review this one.
| Java Streams provide a functional, declarative approach to processing collections of data. | ||
|
|
||
| Instead of writing explicit loops, Streams let you build **pipelines** of operations — transforming data step-by-step in a clean, readable way. | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also introduce the intermediate and terminal methods to introduce the possiblity of chaining function.
- I would also introduce the usage of the lambda with only one function to execute which makes more readable
| List<String> names = List.of("Arjun", "Riya", "Sam", "Aman"); | ||
|
|
||
| names.stream() | ||
| .filter(n -> n.startsWith("A")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would introduce, as an intermediate operation:
- filter
- map, mapToInt, mapToLong...
- peek
- limit
- distinct
- sorted
- skip
And Termination operations:
- collect
- count
- reduce
- anyMatch
- findFirst
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree it would be good to introduce some of theses operations. Note we don't need a complete list, but having some would be great.
kahgoh
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for wanting to contribute the Streams concept, but there is already an open PR for this (#2983) so I'm going to put this one on hold by putting this in "requested changes" state. Admittedly, the other one hasn't had activity for a while, so I've pinged the other PR's author on that one. If there's no reply or if they've lost interest, I'll come back to review this one.
Its been a few weeks without a response to the other PR, so I think we can continue with this one.
| ### Creating Streams | ||
| Streams can be created from collections, arrays, or I/O channels: | ||
| ```java | ||
| List<Integer> numbers = List.of(1, 2, 3, 4, 5); | ||
| Stream<Integer> stream = numbers.stream(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This content is incomplete
| List<String> names = List.of("Arjun", "Riya", "Sam", "Aman"); | ||
|
|
||
| names.stream() | ||
| .filter(n -> n.startsWith("A")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree it would be good to introduce some of theses operations. Note we don't need a complete list, but having some would be great.
|
|
||
| A **Stream** is a sequence of elements that supports operations like filtering, mapping, and reducing. | ||
| It allows you to transform and analyze collections without using traditional loops. | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is also missing how to get a Stream
pull request
Reviewer Resources:
Track Policies