Skip to content
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

Refaster rules that encourage filtering before sorting #386

Closed
1 of 2 tasks
Stephan202 opened this issue Dec 4, 2022 · 1 comment · Fixed by #393
Closed
1 of 2 tasks

Refaster rules that encourage filtering before sorting #386

Stephan202 opened this issue Dec 4, 2022 · 1 comment · Fixed by #393
Labels
Milestone

Comments

@Stephan202
Copy link
Member

Stephan202 commented Dec 4, 2022

Problem

Given a stream of elements that must be filtered and sorted, it is generally more efficient to do the former first, so that the subsequent sorting step involves fewer elements. This applies to Stream, IntStream, LongStream, DoubleStream and Flux types.

Description of the proposed new feature

  • Support a stylistic preference.
  • Avoid a common gotcha, or potential problem.

Rewrite:

stream.sorted().filter(pred)

to:

stream.filter(pred).sorted()

Do the same for the other types mentioned above, as well as Comparator-accepting sort method overloads.

Considerations

One nice advantage of the proposed rewrite rules is that these simplifications might subsequently kick in.

@CoolTomatos
Copy link
Contributor

I would like to pick this one up for the cute new Christmax edition sticker haha.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

2 participants