@@ -266,7 +266,7 @@ import Prelude
266-- lmapM f = Unfold.many (Unfold.functionM f)
266-- lmapM f = Unfold.many (Unfold.functionM f)
269−-- /Pre-release/
269+-- /Since: 0.8.0/
270{-# INLINE_NORMAL lmapM #-}
270{-# INLINE_NORMAL lmapM #-}
271lmapM :: Monad m => (a -> m c) -> Unfold m c b -> Unfold m a b
271lmapM :: Monad m => (a -> m c) -> Unfold m c b -> Unfold m a b
272lmapM f (Unfold ustep uinject) = Unfold ustep (f >=> uinject)
272lmapM f (Unfold ustep uinject) = Unfold ustep (f >=> uinject)
@@ -387,6 +387,11 @@ fold (Fold fstep initial extract) (Unfold ustep inject) a = do
387 Skip s -> go SPEC fs s
387 Skip s -> go SPEC fs s
388 Stop -> extract fs
388 Stop -> extract fs
390+-- | Apply a monadic function to each element of the stream and replace it
391+-- with the output of the resulting action.
390{-# INLINE_NORMAL mapM #-}
395{-# INLINE_NORMAL mapM #-}
391mapM :: Monad m => (b -> m c) -> Unfold m a b -> Unfold m a c
396mapM :: Monad m => (b -> m c) -> Unfold m a b -> Unfold m a c
392mapM f (Unfold ustep uinject) = Unfold step uinject
397mapM f (Unfold ustep uinject) = Unfold step uinject
@@ -449,7 +454,8 @@ fromStreamK = Unfold step return
449-- | Convert a stream into an 'Unfold'. Note that a stream converted to an
454-- | Convert a stream into an 'Unfold'. Note that a stream converted to an
450-- 'Unfold' may not be as efficient as an 'Unfold' in some situations.
455-- 'Unfold' may not be as efficient as an 'Unfold' in some situations.
452−-- /Pre-release/
457+-- /Since: 0.8.0/
453{-# INLINE_NORMAL fromStream #-}
459{-# INLINE_NORMAL fromStream #-}
454fromStream :: (K.IsStream t, Monad m) => Unfold m (t m a) a
460fromStream :: (K.IsStream t, Monad m) => Unfold m (t m a) a
455fromStream = lmap K.toStream fromStreamK
461fromStream = lmap K.toStream fromStreamK
@@ -491,6 +497,9 @@ consM action unf = Unfold step inject
491 Stop -> return Stop
497 Stop -> return Stop
493-- | Convert a list of pure values to a 'Stream'
499-- | Convert a list of pure values to a 'Stream'
494{-# INLINE_LATE fromList #-}
503{-# INLINE_LATE fromList #-}
495fromList :: Monad m => Unfold m [a] a
504fromList :: Monad m => Unfold m [a] a
496fromList = Unfold step inject
505fromList = Unfold step inject
@@ -501,6 +510,9 @@ fromList = Unfold step inject
501 step [] = return Stop
510 step [] = return Stop
503-- | Convert a list of monadic values to a 'Stream'
512-- | Convert a list of monadic values to a 'Stream'
504{-# INLINE_LATE fromListM #-}
516{-# INLINE_LATE fromListM #-}
505fromListM :: Monad m => Unfold m [m a] a
517fromListM :: Monad m => Unfold m [m a] a
506fromListM = Unfold step inject
518fromListM = Unfold step inject
@@ -516,7 +528,7 @@ fromListM = Unfold step inject
517-- | Generates a stream replicating the seed @n@ times.
529-- | Generates a stream replicating the seed @n@ times.
519−-- /Pre-release/
531+-- /Since: 0.8.0/
521{-# INLINE replicateM #-}
533{-# INLINE replicateM #-}
522replicateM :: Monad m => Int -> Unfold m (m a) a
534replicateM :: Monad m => Int -> Unfold m (m a) a
@@ -536,7 +548,7 @@ replicateM n = Unfold step inject
537-- | Generates an infinite stream repeating the seed.
549-- | Generates an infinite stream repeating the seed.
539−-- /Pre-release/
551+-- /Since: 0.8.0/
541{-# INLINE repeatM #-}
553{-# INLINE repeatM #-}
542repeatM :: Monad m => Unfold m (m a) a
554repeatM :: Monad m => Unfold m (m a) a
@@ -548,7 +560,7 @@ repeatM = Unfold step return
548-- | Generates an infinite stream starting with the given seed and applying the
560-- | Generates an infinite stream starting with the given seed and applying the
549-- given function repeatedly.
561-- given function repeatedly.
551−-- /Pre-release/
563+-- /Since: 0.8.0/
553{-# INLINE iterateM #-}
565{-# INLINE iterateM #-}
554iterateM :: Monad m => (a -> m a) -> Unfold m (m a) a
566iterateM :: Monad m => (a -> m a) -> Unfold m (m a) a
@@ -586,6 +598,8 @@ fromIndicesM gen = Unfold step return
586-- >>> Unfold.fold Fold.toList u [1..100]
598-- >>> Unfold.fold Fold.toList u [1..100]
589{-# INLINE_NORMAL take #-}
603{-# INLINE_NORMAL take #-}
590take :: Monad m => Int -> Unfold m a b -> Unfold m a b
604take :: Monad m => Int -> Unfold m a b -> Unfold m a b
591take n (Unfold step1 inject1) = Unfold step inject
605take n (Unfold step1 inject1) = Unfold step inject
@@ -602,6 +616,10 @@ take n (Unfold step1 inject1) = Unfold step inject
602 Stop -> Stop
616 Stop -> Stop
603 step (_, _) = return Stop
617 step (_, _) = return Stop
619+-- | Same as 'takeWhile' but with a monadic predicate.
605{-# INLINE_NORMAL takeWhileM #-}
623{-# INLINE_NORMAL takeWhileM #-}
606takeWhileM :: Monad m => (b -> m Bool) -> Unfold m a b -> Unfold m a b
624takeWhileM :: Monad m => (b -> m Bool) -> Unfold m a b -> Unfold m a b
607takeWhileM f (Unfold step1 inject1) = Unfold step inject1
625takeWhileM f (Unfold step1 inject1) = Unfold step inject1
@@ -616,10 +634,19 @@ takeWhileM f (Unfold step1 inject1) = Unfold step inject1
616 Skip s -> return $ Skip s
634 Skip s -> return $ Skip s
617 Stop -> return Stop
635 Stop -> return Stop
637+-- | End the stream generated by the 'Unfold' as soon as the predicate fails
619{-# INLINE takeWhile #-}
642{-# INLINE takeWhile #-}
620takeWhile :: Monad m => (b -> Bool) -> Unfold m a b -> Unfold m a b
643takeWhile :: Monad m => (b -> Bool) -> Unfold m a b -> Unfold m a b
621takeWhile f = takeWhileM (return . f)
644takeWhile f = takeWhileM (return . f)
646+-- | Same as 'filter' but with a monadic predicate.
623{-# INLINE_NORMAL filterM #-}
650{-# INLINE_NORMAL filterM #-}
624filterM :: Monad m => (b -> m Bool) -> Unfold m a b -> Unfold m a b
651filterM :: Monad m => (b -> m Bool) -> Unfold m a b -> Unfold m a b
625filterM f (Unfold step1 inject1) = Unfold step inject1
652filterM f (Unfold step1 inject1) = Unfold step inject1
@@ -634,13 +661,17 @@ filterM f (Unfold step1 inject1) = Unfold step inject1
634 Skip s -> return $ Skip s
661 Skip s -> return $ Skip s
635 Stop -> return Stop
662 Stop -> return Stop
664+-- | Include only those elements that pass a predicate.
637{-# INLINE filter #-}
668{-# INLINE filter #-}
638filter :: Monad m => (b -> Bool) -> Unfold m a b -> Unfold m a b
669filter :: Monad m => (b -> Bool) -> Unfold m a b -> Unfold m a b
639filter f = filterM (return . f)
670filter f = filterM (return . f)
641-- | @drop n unf@ drops @n@ elements from the stream generated by @unf@.
672-- | @drop n unf@ drops @n@ elements from the stream generated by @unf@.
643−-- /Pre-release/
674+-- /Since: 0.8.0/
645{-# INLINE_NORMAL drop #-}
676{-# INLINE_NORMAL drop #-}
646drop :: Monad m => Int -> Unfold m a b -> Unfold m a b
677drop :: Monad m => Int -> Unfold m a b -> Unfold m a b
@@ -672,7 +703,7 @@ drop n (Unfold step inject) = Unfold step' inject'
672-- | @dropWhileM f unf@ drops elements from the stream generated by @unf@ while
703-- | @dropWhileM f unf@ drops elements from the stream generated by @unf@ while
673-- the condition holds true. The condition function @f@ is /monadic/ in nature.
704-- the condition holds true. The condition function @f@ is /monadic/ in nature.
675−-- /Pre-release/
706+-- /Since: 0.8.0/
677{-# INLINE_NORMAL dropWhileM #-}
708{-# INLINE_NORMAL dropWhileM #-}
678dropWhileM :: Monad m => (b -> m Bool) -> Unfold m a b -> Unfold m a b
709dropWhileM :: Monad m => (b -> m Bool) -> Unfold m a b -> Unfold m a b
@@ -706,7 +737,7 @@ dropWhileM f (Unfold step inject) = Unfold step' inject'
707-- | Similar to 'dropWhileM' but with a pure condition function.
738-- | Similar to 'dropWhileM' but with a pure condition function.
709−-- /Pre-release/
740+-- /Since: 0.8.0/
711{-# INLINE dropWhile #-}
742{-# INLINE dropWhile #-}
712dropWhile :: Monad m => (b -> Bool) -> Unfold m a b -> Unfold m a b
743dropWhile :: Monad m => (b -> Bool) -> Unfold m a b -> Unfold m a b