Skip to content

index for vector throws exception on negative indices #172

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

Closed
sniperrifle2004 opened this issue Dec 18, 2018 · 2 comments
Closed

index for vector throws exception on negative indices #172

sniperrifle2004 opened this issue Dec 18, 2018 · 2 comments

Comments

@sniperrifle2004
Copy link
Contributor

Similar to #114 the behaviour of index for negative indices is not what I would expect from index. Instead of the behaviour of (!?) which returns nothing for out of bounds on either side, an out of bounds exception is thrown from from (!).

I would expect index to return Nothing even on input that is never valid for the underlying sequence. When I am using index in practice it is often to not have to care about the exact bounds myself, instead delegating that to the underlying sequence. So if exceptions occur or unreasonable results appear on unusual indices that benefit of using index disappears at least partly.

@snoyberg
Copy link
Owner

Good catch, this is unintentional and simply some bad code. We should be returning Nothing in the case of negatives. Are you interested in PRing a fix?

@sniperrifle2004
Copy link
Contributor Author

Sure, I'll take a look.

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

No branches or pull requests

2 participants