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

@tlinkowski tlinkowski commented Aug 12, 2016

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

@lukaseder lukaseder commented Aug 12, 2016

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?

Loading

@amaembo
Copy link

@amaembo 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.

Loading

@tlinkowski
Copy link
Author

@tlinkowski tlinkowski commented Aug 12, 2016

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.

Loading

@lukaseder
Copy link
Member

@lukaseder lukaseder commented Aug 12, 2016

Excellent, looking forward!

Loading

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

@lukaseder lukaseder commented Aug 15, 2016

Implementation in #243

Loading

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

Successfully merging a pull request may close this issue.

None yet
3 participants