Closed vdukhovni closed 3 years ago
uncons
having a Maybe
in its return type mirrors the standard library, but in this case I think the two functions should be merged into a single one named uncons
who returns an Either
and avoids the crashes. That would be another breaking change.
So I think you're suggesting to rename nextByte
to uncons
(deleting the original), and either rename nextChar
to uncons
, or clone the Word8
uncons adding a w2c
conversion to the return value. The indirection via such a small helper is not especially useful, and the functions are recursive, so don't inline. (We could move the recursion into a where go = ...
and just have the exposed function call go
, which would make inlining possible, and is perhaps the right thing to do...).
Should addressing this go into #42 or a new separate PR?
New PR, I'd say.
Speaking of uncons
there's another related case:
unconsChunk :: Monad m => ByteStream m r -> m (Maybe (B.ByteString, ByteStream m r))
nextChunk :: Monad m => ByteStream m r -> m (Either r (B.ByteString, ByteStream m r))
Again the first is redundant, the second is the more appropriate interface. I don't know what your thoughts are about keeping both, or likewise keeping just nextChunk
renamed to uncons
, or ...
Let's rename those as well.
It is simpler for me to add these to #42, or else wait until #42 is merged and then open a new PR. I prefer the former, but if a new PR is needed, I'll wait for #42 to land.
Adding to #42 should be fine.
The uncons implementation for
Streaming.ByteString
has a somewhat unfortunate choice of return type that loses the stream's terminal value when it is empty. It is also unsafe, if the first chunk of the stream is an empty ByteString, it will crash (this defect is addressed in thenextByte
function below):to make up for this deficit, there a more natural variant named nextByte
These have variants in
Streaming.ByteString.Char8
named uncons and nextChar, defined and documented as shown below, but note that the haddock documentation of thisuncons
is wrong, it does not return aMaybe
, rather it is in fact almost functionally identical tonextChar
, except that it reproduces the potential crash in theWord8
uncons when the first chunk is empty:What should we do? At the very least the crashes should be fixed, but which is the correct
uncons
type? Should they remain unexpectedly different? At the very least the documentation should reflect reality...