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 Seq.indexOf method(s) #242

Closed
tlinkowski opened this issue Aug 12, 2016 · 5 comments
Closed

Add Seq.indexOf method(s) #242

tlinkowski opened this issue Aug 12, 2016 · 5 comments

Comments

@tlinkowski
Copy link

Since we have Seq.contains and Seq.get(index), it'd be nice to also have long indexOf(T item) or OptionalLong indexOf(T item).

Incidentally, we could also have long/OptionalLong indexOf(Predicate<? super T> predicate) which would be equivalent to Guava's Iterators.indexOf.

@lukaseder
Copy link
Member

Excellent idea. I agree with both proposed APIs:

OptionalLong indexOf(T item)
OptionalLong indexOf(Predicate<? super T> predicate)

The latter is also not unexpected, given the existing Seq.findFirst(Predicate). I think we should prefer OptionalLong over the historic -1 encoding in a primitive long as it fits better into the Stream / Seq API.

Would you be interested in providing a pull request for this?

@amaembo
Copy link

amaembo commented Aug 12, 2016

I have such methods returning OptionalLong. Returning -1 seems not consistent with other Stream API methods. Though probably a matter of taste.

@tlinkowski
Copy link
Author

I am also in favor of OptionalLong.

OK, I'll create a pull request for this over the weekend. I propose an implementation utilizing iterator() and mirroring Guava's Iterators.indexOf.

@lukaseder
Copy link
Member

Excellent, looking forward!

tlinkowski pushed a commit to tlinkowski/jOOL that referenced this issue Aug 13, 2016
lukaseder added a commit that referenced this issue Aug 15, 2016
@lukaseder
Copy link
Member

Implementation in #243

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

No branches or pull requests

3 participants