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

Implement count(Predicate<T>) #260

Closed
Suicolen opened this issue Mar 21, 2022 · 0 comments
Closed

Implement count(Predicate<T>) #260

Suicolen opened this issue Mar 21, 2022 · 0 comments
Assignees
Milestone

Comments

@Suicolen
Copy link

Suicolen commented Mar 21, 2022

I believe it is somewhat common to filter a stream and count the number of elements, for example to count the number of even numbers in a range u would write:
long evenCount = IntStreamEx.range(n).filter(x -> x % 2 == 0).count();
However a count method that takes in a Predicate and only counts the element if it matches the predicate would be more convenient imo.
Example:
long evenCount = IntStreamEx.range(n).count(x -> x % 2 == 0);

Alternatively the method could be called countIf

@amaembo amaembo self-assigned this Sep 24, 2022
amaembo added a commit that referenced this issue Sep 24, 2022
@amaembo amaembo closed this as completed Sep 24, 2022
@amaembo amaembo added this to the 0.8.2 milestone Sep 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants