Skip to content

Commit 114fde6

Browse files
author
Jaro Reinders
committed
Fix drop issue
1 parent 0936362 commit 114fde6

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

vector-stream/src/Data/Stream/Monadic.hs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -387,15 +387,19 @@ take n (Stream step t) = n `seq` Stream step' (t, 0)
387387
-- | All but the first @n@ elements
388388
drop :: Monad m => Int -> Stream m a -> Stream m a
389389
{-# INLINE_FUSED drop #-}
390-
drop n (Stream step t) = Stream (step' n) t
390+
drop n (Stream step t) = Stream step' (t, n)
391391
where
392392
{-# INLINE_INNER step' #-}
393-
step' i s | i > 0 = do
394-
r <- step s
395-
case r of
396-
Yield _ s' -> step' (i - 1) s'
397-
Done -> return Done
398-
| otherwise = step s
393+
step' (s, i) | i > 0 = do
394+
r <- step s
395+
case r of
396+
Yield _ s' -> step' (s', i - 1)
397+
Done -> return Done
398+
| otherwise = liftM (\r ->
399+
case r of
400+
Yield x s' -> Yield x (s', i)
401+
Done -> Done
402+
) (step s)
399403

400404

401405
-- Mapping

0 commit comments

Comments
 (0)