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

Add IterableUtils.any() method #551

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

spijkercenter
Copy link

  • Introduces a new utility method 'any()' in IterableUtils
  • Returns an Optional containing the first element of an Iterable
  • Handles null and empty iterables, returning an empty Optional

The method is named 'any()' to reflect its behavior of returning any element from the Iterable (specifically, the first one). This naming is consistent with similar concepts in other programming languages and libraries where 'any' often denotes "give me any element that satisfies a condition" - in this case, the condition is simply existence within the Iterable.

This addition provides a convenient way to safely retrieve the first element of an Iterable, wrapped in an Optional, with null-safety built-in.

- Introduces a new utility method 'any()' in IterableUtils
- Returns an Optional containing the first element of an Iterable
- Handles null and empty iterables, returning an empty Optional

The method is named 'any()' to reflect its behavior of returning any
element from the Iterable (specifically, the first one). This naming
is consistent with similar concepts in other programming languages
and libraries where 'any' often denotes "give me any element that
satisfies a condition" - in this case, the condition is simply
existence within the Iterable.

This addition provides a convenient way to safely retrieve the first 
element of an Iterable, wrapped in an Optional, with null-safety built-in.
Copy link
Member

@garydgregory garydgregory left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @spijkercenter

-1

  • This PR does not compile.
  • Please validate your submissions to avoid wasting the maintainers' time. Compiling code is the most basic requirement.
  • Unfortunately, the PR also has zero unit tests, so it can't be validated.
  • This class does not use Optional and I don't think we want to add variants
  • Try to use the existing APIs, like get() and first() and use Optional in your code

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 this pull request may close these issues.

2 participants