Nothing Special   »   [go: up one dir, main page]

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

Safe indexing functions #231

Closed
cole-miller opened this issue Jun 21, 2020 · 2 comments · Fixed by #261
Closed

Safe indexing functions #231

cole-miller opened this issue Jun 21, 2020 · 2 comments · Fixed by #261
Milestone

Comments

@cole-miller
Copy link

The index function in Data.ByteString throws an exception if the given index is negative or too large. This makes it cumbersome to deal with possibly-invalid indices: you have to either catch the exception, which doesn't compose well with other Haskell machinery, or replicate the range check in your own code. It would be useful to have a non-throwing version of index of type ByteString -> Int -> Maybe Word8, which would enable more idiomatic handling of bad indices. This would be in line with the existing bytestring functions uncons and unsnoc, which return a Maybe value to deal with empty byte strings.

The same goes for Data.ByteString.Lazy and Data.ByteString.Short, since these also have unsafe index functions.

@sjakobi
Copy link
Member
sjakobi commented Jun 21, 2020

I believe #146 will address this and will hopefully be merged soon.

@cole-miller
Copy link
Author

Ahh, I didn't think to check in pending pull requests. Thanks!

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