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

Comments

@tlinkowski
Copy link
Contributor

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

This comment has been minimized.

Copy link
Member

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?

@amaembo

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link
Contributor Author

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.

@lukaseder

This comment has been minimized.

Copy link
Member

commented Aug 12, 2016

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
Merge pull request #243 from tlinkowski/master
[#242] Add Seq.indexOf method(s)
@lukaseder

This comment has been minimized.

Copy link
Member

commented Aug 15, 2016

Implementation in #243

@lukaseder lukaseder closed this Aug 15, 2016

@lukaseder lukaseder added the R: Fixed label Aug 15, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.