-
Notifications
You must be signed in to change notification settings - Fork 276
Use Java 8 Stream #375
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
Use Java 8 Stream #375
Conversation
| integers[i] = (int) chars[i]; | ||
| } | ||
| return integers; | ||
| return Arrays.stream(chars).map(aChar -> (int) aChar).toArray(Integer[]::new); |
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.
You don't need streams @arturobernalg
Why not just:
final Integer[] integers = new Integer[chars.length];
Arrays.setAll(integers, i -> (int) chars[i]);
?
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.
If I may jump in, personally and strictly personally :), I find stream-map-reduce flow to be somehow more readable. I immediately recognize that we are converting one set of data to another set. It would help even more with proper formatting where each stream operation is in a separate line. It could be argued that using a functional paradigm for data manipulation as of late is - idiomatic in Java.
With setAll approach I (personally) need to think for a moment about what is actually happening.
After all, there is no right way -> both imperative and functional approaches are correct, only matters of personal preference.
| intersection++; | ||
| } | ||
| } | ||
| int intersection = (int) setA.stream().filter(setB::contains).count(); |
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.
Do we still need the local variable?
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.
Whichever way we go, we probably need to Javadoc the truncation (PR) or looping of ints (current master).
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.
inline.
meanwhile I have change your remarks.
|
The code does not compile @arturobernalg |
Codecov Report
@@ Coverage Diff @@
## master #375 +/- ##
============================================
+ Coverage 97.12% 97.15% +0.03%
+ Complexity 2324 2315 -9
============================================
Files 84 84
Lines 5770 5695 -75
Branches 935 895 -40
============================================
- Hits 5604 5533 -71
+ Misses 87 83 -4
Partials 79 79
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
|
@arturobernalg there is nothing to review until the builds are green ;-) |
|
|
Just curious, what is the point to change the code which can be compiled directly to processor commands with code which makes tons of calls with stack usage? |
|
@sergmain in my perspective, streams do bring a lot in readability and maintainability. Regarding performance, it's difficult to say with guessing. I think we need proper performance testing, but as a layman, I don't expect much difference in performance. Streams are already well optimized in Java and I trust that performance difference will be negligible. |
No description provided.