Skip to content

Commit 8b514d4

Browse files
committed
Fusion.Common: Fix take/drop's treatment of negative counts
This fixes #227.
1 parent 76a4999 commit 8b514d4

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Data/Text/Internal/Fusion/Common.hs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -735,8 +735,10 @@ unfoldrNI n f s0 | n < 0 = empty
735735
-- length of the stream.
736736
take :: Integral a => a -> Stream Char -> Stream Char
737737
take n0 (Stream next0 s0 len) =
738-
Stream next (n0 :*: s0) (smaller len (codePointsSize $ fromIntegral n0))
738+
Stream next (n0' :*: s0) (smaller len (codePointsSize $ fromIntegral n0'))
739739
where
740+
n0' = max n0 0
741+
740742
{-# INLINE next #-}
741743
next (n :*: s) | n <= 0 = Done
742744
| otherwise = case next0 s of
@@ -753,8 +755,10 @@ data Drop a s = NS !s
753755
-- is greater than the length of the stream.
754756
drop :: Integral a => a -> Stream Char -> Stream Char
755757
drop n0 (Stream next0 s0 len) =
756-
Stream next (JS n0 s0) (len - codePointsSize (fromIntegral n0))
758+
Stream next (JS n0' s0) (len - codePointsSize (fromIntegral n0'))
757759
where
760+
n0' = max n0 0
761+
758762
{-# INLINE next #-}
759763
next (JS n s)
760764
| n <= 0 = Skip (NS s)

0 commit comments

Comments
 (0)