You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
The
index
function inData.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 ofindex
of typeByteString -> Int -> Maybe Word8
, which would enable more idiomatic handling of bad indices. This would be in line with the existingbytestring
functionsuncons
andunsnoc
, which return aMaybe
value to deal with empty byte strings.The same goes for
Data.ByteString.Lazy
andData.ByteString.Short
, since these also have unsafeindex
functions.The text was updated successfully, but these errors were encountered: