@@ -187,6 +187,9 @@ cons !w (Stream next0 s0 len) = Stream next (C1 s0) (len+1)
187 Yield x s' -> Yield x (C0 s')
187 Yield x s' -> Yield x (C0 s')
188{-# INLINE [0] cons #-}
188{-# INLINE [0] cons #-}
190-- | /O(n)/ Adds a character to the end of a stream.
193-- | /O(n)/ Adds a character to the end of a stream.
191snoc :: Stream Char -> Char -> Stream Char
194snoc :: Stream Char -> Char -> Stream Char
192snoc (Stream next0 xs0 len) w = Stream next (J xs0) (len+1)
195snoc (Stream next0 xs0 len) w = Stream next (J xs0) (len+1)
@@ -762,24 +765,27 @@ take n0 (Stream next0 s0 len) =
762 Yield x s' -> Yield x ((n-1) :*: s')
765 Yield x s' -> Yield x ((n-1) :*: s')
763{-# INLINE [0] take #-}
766{-# INLINE [0] take #-}
768+data Drop a s = NS !s
765-- | /O(n)/ drop n, applied to a stream, returns the suffix of the
771-- | /O(n)/ drop n, applied to a stream, returns the suffix of the
766-- stream after the first @n@ characters, or the empty stream if @n@
772-- stream after the first @n@ characters, or the empty stream if @n@
767-- is greater than the length of the stream.
773-- is greater than the length of the stream.
768drop :: Integral a => a -> Stream Char -> Stream Char
774drop :: Integral a => a -> Stream Char -> Stream Char
769drop n0 (Stream next0 s0 len) =
775drop n0 (Stream next0 s0 len) =
770− Stream next (J n0 :*: s0) (len - fromIntegral (max 0 n0))
776+ Stream next (JS n0 s0) (len - fromIntegral (max 0 n0))
772 {-# INLINE next #-}
778 {-# INLINE next #-}
773− next (J n :*: s)
779+ next (JS n s)
774− | n <= 0 = Skip (N :*: s)
780+ | n <= 0 = Skip (NS s)
775 | otherwise = case next0 s of
781 | otherwise = case next0 s of
776 Done -> Done
782 Done -> Done
777− Skip s' -> Skip (J n :*: s')
783+ Skip s' -> Skip (JS n s')
778− Yield _ s' -> Skip (J (n-1) :*: s')
784+ Yield _ s' -> Skip (JS (n-1) s')
779− next (N :*: s) = case next0 s of
785+ next (NS s) = case next0 s of
780 Done -> Done
786 Done -> Done
781− Skip s' -> Skip (N :*: s')
787+ Skip s' -> Skip (NS s')
782− Yield x s' -> Yield x (N :*: s')
788+ Yield x s' -> Yield x (NS s')
783{-# INLINE [0] drop #-}
789{-# INLINE [0] drop #-}
785-- | takeWhile, applied to a predicate @p@ and a stream, returns the
791-- | takeWhile, applied to a predicate @p@ and a stream, returns the
@@ -915,21 +921,25 @@ findIndicesI p (Stream next s0 _len) = loop_findIndex 0 s0
915-------------------------------------------------------------------------------
921-------------------------------------------------------------------------------
916-- * Zipping
922-- * Zipping
925+data Zip a b m = Z1 !a !b
918-- | zipWith generalises 'zip' by zipping with the function given as
928-- | zipWith generalises 'zip' by zipping with the function given as
919-- the first argument, instead of a tupling function.
929-- the first argument, instead of a tupling function.
920zipWith :: (a -> a -> b) -> Stream a -> Stream a -> Stream b
930zipWith :: (a -> a -> b) -> Stream a -> Stream a -> Stream b
921zipWith f (Stream next0 sa0 len1) (Stream next1 sb0 len2) =
931zipWith f (Stream next0 sa0 len1) (Stream next1 sb0 len2) =
922− Stream next (T3 sa0 sb0 N) (smaller len1 len2)
932+ Stream next (Z1 sa0 sb0) (smaller len1 len2)
924− next (T3 sa sb N) = case next0 sa of
934+ next (Z1 sa sb) = case next0 sa of
925− Done -> Done
935+ Done -> Done
926− Skip sa' -> Skip (T3 sa' sb N)
936+ Skip sa' -> Skip (Z1 sa' sb)
927− Yield a sa' -> Skip (T3 sa' sb (J a))
937+ Yield a sa' -> Skip (Z2 sa' sb a)
929− next (T3 sa' sb (J a)) = case next1 sb of
939+ next (Z2 sa' sb a) = case next1 sb of
930− Done -> Done
940+ Done -> Done
931− Skip sb' -> Skip (T3 sa' sb' (J a))
941+ Skip sb' -> Skip (Z2 sa' sb' a)
932− Yield b sb' -> Yield (f a b) (T3 sa' sb' N)
942+ Yield b sb' -> Yield (f a b) (Z1 sa' sb')
933{-# INLINE [0] zipWith #-}
943{-# INLINE [0] zipWith #-}
935-- | /O(n)/ The 'countCharI' function returns the number of times the
945-- | /O(n)/ The 'countCharI' function returns the number of times the