Add new Streams concept with intro and resources#3041
Add new Streams concept with intro and resources#3041ZaildarAnmol wants to merge 1 commit intoexercism:mainfrom
Conversation
There was a problem hiding this comment.
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.
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.
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.
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.
There was a problem hiding this comment.
agree. I would think that at least the collect and findfirst or anyMatch should be introduced:
- Collect is one of the terminal operation that is widely used.
- a terminal operation liike findfirst to show we can return only one element and anyMatch to show that a stream can return a boolean
kahgoh
left a comment
There was a problem hiding this comment.
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(); |
| List<String> names = List.of("Arjun", "Riya", "Sam", "Aman"); | ||
|
|
||
| names.stream() | ||
| .filter(n -> n.startsWith("A")) |
There was a problem hiding this comment.
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.
I think this is also missing how to get a Stream
pull request
Reviewer Resources:
Track Policies