reChunk is a bit weird about empty chunks
- Dominant language
- Haskell
- Stars
- 5
- Forks
- 11
- PR merge metrics
- No merged PRs in 30d
Description
`reChunk` is implemented like this:
```haskell
reChunk :: [ByteString] -> [ByteString]
reChunk [] = []
reChunk (c:cs) = case B.length c `divMod` 2 of
(_, 0) -> c : reChunk cs
(n, _) -> case B.splitAt (n * 2) c of
~(m, q) -> m : cont_ q cs
where
cont_ q [] = [q]
cont_ q (a:as) = case B.splitAt 1 a of
~(x, y) -> let q' = B.append q x
in if B.length q' == 2
then
let as' = if B.null y then as else y:as
in q' : reChunk as'
else cont_ q' as
```
In the main body of the function, there is no check for empty chunks; those just pass through. In the `cont_` worker, however, there's some effort (the `B.null y` check) to avoid producing an empty chunk. Why this apparent inconsistency? I would expect to either check for empty chunks both places or neither.
Contributor guide
Assessment
This issue has not been assessed yet.