Skip to content

Commit

Permalink
Handle n < 0 better
Browse files Browse the repository at this point in the history
  • Loading branch information
elikoga committed Oct 27, 2020
1 parent dff5ef7 commit 001184b
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions Data/ByteString/Lazy/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,11 @@ concat css0 = to css0
-- | Repeats the given ByteString n times.
times :: Integral a => a -> ByteString -> ByteString
times 0 _ = Empty
times n Empty
times n lbs0
| n < 0 = error "stimes: non-negative multiplier expected"
| otherwise = Empty
times n lbs0@(Chunk bs lbs)
| n < 0 = error "stimes: non-negative multiplier expected"
| otherwise = Chunk bs (go lbs)
| otherwise = case lbs0 of
Empty -> Empty
Chunk bs lbs -> Chunk bs (go lbs)
where
go Empty = times (n-1) lbs0
go (Chunk c cs) = Chunk c (go cs)
Expand Down

0 comments on commit 001184b

Please sign in to comment.