@@ -265,8 +265,7 @@ foldrT f z s = D.foldrT f z (toStreamD s)
265-- >>> Stream.fold Fold.drain $ Stream.mapM putStr s
265-- >>> Stream.fold Fold.drain $ Stream.mapM putStr s
268−-- /Pre-release/
268+-- @since 0.9.0
270{-# INLINE mapM #-}
269{-# INLINE mapM #-}
271mapM :: Monad m => (a -> m b) -> Stream m a -> Stream m b
270mapM :: Monad m => (a -> m b) -> Stream m a -> Stream m b
272mapM f m = fromStreamK $ D.toStreamK $ D.mapM f $ toStreamD m
271mapM f m = fromStreamK $ D.toStreamK $ D.mapM f $ toStreamD m
@@ -281,6 +280,7 @@ mapM f m = fromStreamK $ D.toStreamK $ D.mapM f $ toStreamD m
281-- >>> Stream.fold Fold.drain $ Stream.sequence s
280-- >>> Stream.fold Fold.drain $ Stream.sequence s
284{-# INLINE sequence #-}
284{-# INLINE sequence #-}
285sequence :: Monad m => Stream m (m a) -> Stream m a
285sequence :: Monad m => Stream m (m a) -> Stream m a
286sequence = mapM id
286sequence = mapM id
@@ -307,6 +307,7 @@ sequence = mapM id
308-- Compare with 'trace'.
308-- Compare with 'trace'.
310{-# INLINE tap #-}
311{-# INLINE tap #-}
311tap :: Monad m => FL.Fold m a b -> Stream m a -> Stream m a
312tap :: Monad m => FL.Fold m a b -> Stream m a -> Stream m a
312tap f xs = fromStreamD $ D.tap f (toStreamD xs)
313tap f xs = fromStreamD $ D.tap f (toStreamD xs)
@@ -363,6 +364,7 @@ trace_ eff = fromStreamD . D.mapM (\x -> eff >> return x) . toStreamD
364-- See also: 'usingStateT'
365-- See also: 'usingStateT'
367-- EXPLANATION:
369-- EXPLANATION:
368-- >>> scanl' step z = Stream.scan (Fold.foldl' step z)
370-- >>> scanl' step z = Stream.scan (Fold.foldl' step z)
@@ -407,6 +409,7 @@ trace_ eff = fromStreamD . D.mapM (\x -> eff >> return x) . toStreamD
407-- lazy expressions inside the accumulator, it is recommended that a strict
409-- lazy expressions inside the accumulator, it is recommended that a strict
408-- data structure is used for accumulator.
410-- data structure is used for accumulator.
410{-# INLINE scan #-}
413{-# INLINE scan #-}
411scan :: Monad m => Fold m a b -> Stream m a -> Stream m b
414scan :: Monad m => Fold m a b -> Stream m a -> Stream m b
412scan fld m = fromStreamD $ D.scanOnce fld $ toStreamD m
415scan fld m = fromStreamD $ D.scanOnce fld $ toStreamD m
@@ -414,7 +417,7 @@ scan fld m = fromStreamD $ D.scanOnce fld $ toStreamD m
414-- | Like 'scan' but restarts scanning afresh when the scanning fold
417-- | Like 'scan' but restarts scanning afresh when the scanning fold
415-- terminates.
418-- terminates.
417−-- /Pre-release/
420+-- @since 0.9.0
418{-# INLINE scanMany #-}
421{-# INLINE scanMany #-}
419scanMany :: Monad m => Fold m a b -> Stream m a -> Stream m b
422scanMany :: Monad m => Fold m a b -> Stream m a -> Stream m b
420scanMany fld m = fromStreamD $ D.scanMany fld $ toStreamD m
423scanMany fld m = fromStreamD $ D.scanMany fld $ toStreamD m
@@ -444,6 +447,7 @@ with f comb g = fmap snd . comb g . f
444-- >>> filter p = Stream.mapMaybe (\x -> if p x then Just x else Nothing)
447-- >>> filter p = Stream.mapMaybe (\x -> if p x then Just x else Nothing)
445-- >>> filter p = Stream.scanMaybe (Fold.filtering p)
448-- >>> filter p = Stream.scanMaybe (Fold.filtering p)
447{-# INLINE filter #-}
451{-# INLINE filter #-}
448filter :: Monad m => (a -> Bool) -> Stream m a -> Stream m a
452filter :: Monad m => (a -> Bool) -> Stream m a -> Stream m a
449-- filter p = scanMaybe (FL.filtering p)
453-- filter p = scanMaybe (FL.filtering p)
@@ -454,6 +458,7 @@ filter p m = fromStreamD $ D.filter p $ toStreamD m
454-- >>> f p x = p x >>= \r -> return $ if r then Just x else Nothing
458-- >>> f p x = p x >>= \r -> return $ if r then Just x else Nothing
455-- >>> filterM p = Stream.mapMaybeM (f p)
459-- >>> filterM p = Stream.mapMaybeM (f p)
457{-# INLINE filterM #-}
462{-# INLINE filterM #-}
458filterM :: Monad m => (a -> m Bool) -> Stream m a -> Stream m a
463filterM :: Monad m => (a -> m Bool) -> Stream m a -> Stream m a
459filterM p m = fromStreamD $ D.filterM p $ toStreamD m
464filterM p m = fromStreamD $ D.filterM p $ toStreamD m
@@ -493,6 +498,7 @@ uniqBy eq = catMaybes . rollingMap f
494-- >>> uniq = Stream.uniqBy (==)
499-- >>> uniq = Stream.uniqBy (==)
496{-# INLINE uniq #-}
502{-# INLINE uniq #-}
497uniq :: (Eq a, Monad m) => Stream m a -> Stream m a
503uniq :: (Eq a, Monad m) => Stream m a -> Stream m a
498-- uniq = scanMaybe FL.uniq
504-- uniq = scanMaybe FL.uniq
@@ -539,6 +545,7 @@ repeated = undefined
539-- >>> Stream.fold Fold.toList $ Stream.deleteBy (==) 3 input
545-- >>> Stream.fold Fold.toList $ Stream.deleteBy (==) 3 input
540-- [1,3,5]
546-- [1,3,5]
542{-# INLINE deleteBy #-}
549{-# INLINE deleteBy #-}
543deleteBy :: Monad m => (a -> a -> Bool) -> a -> Stream m a -> Stream m a
550deleteBy :: Monad m => (a -> a -> Bool) -> a -> Stream m a -> Stream m a
544-- deleteBy cmp x = scanMaybe (FL.deleteBy cmp x)
551-- deleteBy cmp x = scanMaybe (FL.deleteBy cmp x)
@@ -550,6 +557,7 @@ deleteBy cmp x m = fromStreamD $ D.deleteBy cmp x (toStreamD m)
551-- | Same as 'takeWhile' but with a monadic predicate.
558-- | Same as 'takeWhile' but with a monadic predicate.
553{-# INLINE takeWhileM #-}
561{-# INLINE takeWhileM #-}
554takeWhileM :: Monad m => (a -> m Bool) -> Stream m a -> Stream m a
562takeWhileM :: Monad m => (a -> m Bool) -> Stream m a -> Stream m a
555-- takeWhileM p = scanMaybe (FL.takingEndByM_ (\x -> not <$> p x))
563-- takeWhileM p = scanMaybe (FL.takingEndByM_ (\x -> not <$> p x))
@@ -558,6 +566,7 @@ takeWhileM p m = fromStreamD $ D.takeWhileM p $ toStreamD m
558-- | Drop elements in the stream as long as the predicate succeeds and then
566-- | Drop elements in the stream as long as the predicate succeeds and then
559-- take the rest of the stream.
567-- take the rest of the stream.
561{-# INLINE dropWhile #-}
570{-# INLINE dropWhile #-}
562dropWhile :: Monad m => (a -> Bool) -> Stream m a -> Stream m a
571dropWhile :: Monad m => (a -> Bool) -> Stream m a -> Stream m a
563-- dropWhile p = scanMaybe (FL.droppingWhile p)
572-- dropWhile p = scanMaybe (FL.droppingWhile p)
@@ -565,6 +574,7 @@ dropWhile p m = fromStreamD $ D.dropWhile p $ toStreamD m
566-- | Same as 'dropWhile' but with a monadic predicate.
575-- | Same as 'dropWhile' but with a monadic predicate.
568{-# INLINE dropWhileM #-}
578{-# INLINE dropWhileM #-}
569dropWhileM :: Monad m => (a -> m Bool) -> Stream m a -> Stream m a
579dropWhileM :: Monad m => (a -> m Bool) -> Stream m a -> Stream m a
570-- dropWhileM p = scanMaybe (FL.droppingWhileM p)
580-- dropWhileM p = scanMaybe (FL.droppingWhileM p)
@@ -583,6 +593,7 @@ dropWhileM p m = fromStreamD $ D.dropWhileM p $ toStreamD m
583-- >>> Stream.fold Fold.toList $ Stream.insertBy compare 2 input
593-- >>> Stream.fold Fold.toList $ Stream.insertBy compare 2 input
584-- [1,2,3,5]
594-- [1,2,3,5]
586{-# INLINE insertBy #-}
597{-# INLINE insertBy #-}
587insertBy ::Monad m => (a -> a -> Ordering) -> a -> Stream m a -> Stream m a
598insertBy ::Monad m => (a -> a -> Ordering) -> a -> Stream m a -> Stream m a
588insertBy cmp x m = fromStreamD $ D.insertBy cmp x (toStreamD m)
599insertBy cmp x m = fromStreamD $ D.insertBy cmp x (toStreamD m)
@@ -593,6 +604,7 @@ insertBy cmp x m = fromStreamD $ D.insertBy cmp x (toStreamD m)
593-- >>> Stream.fold Fold.toList $ Stream.intersperse ',' input
604-- >>> Stream.fold Fold.toList $ Stream.intersperse ',' input
594-- "h,e,l,l,o"
605-- "h,e,l,l,o"
596{-# INLINE intersperse #-}
608{-# INLINE intersperse #-}
597intersperse :: Monad m => a -> Stream m a -> Stream m a
609intersperse :: Monad m => a -> Stream m a -> Stream m a
598intersperse a = fromStreamD . D.intersperse a . toStreamD
610intersperse a = fromStreamD . D.intersperse a . toStreamD
@@ -691,6 +703,7 @@ interspersePrefix_ m = mapM (\x -> void m >> return x)
691-- >>> sleep n = liftIO $ threadDelay $ round $ n * 1000000
703-- >>> sleep n = liftIO $ threadDelay $ round $ n * 1000000
692-- >>> delay n = Stream.intersperseM_ $ sleep n
704-- >>> delay n = Stream.intersperseM_ $ sleep n
694{-# INLINE delay #-}
707{-# INLINE delay #-}
695delay :: MonadIO m => Double -> Stream m a -> Stream m a
708delay :: MonadIO m => Double -> Stream m a -> Stream m a
696delay n = intersperseM_ $ liftIO $ threadDelay $ round $ n * 1000000
709delay n = intersperseM_ $ liftIO $ threadDelay $ round $ n * 1000000
@@ -758,6 +771,7 @@ reassembleBy = undefined
758-- >>> Stream.fold Fold.toList $ Stream.indexed $ Stream.fromList "hello"
771-- >>> Stream.fold Fold.toList $ Stream.indexed $ Stream.fromList "hello"
759-- [(0,'h'),(1,'e'),(2,'l'),(3,'l'),(4,'o')]
772-- [(0,'h'),(1,'e'),(2,'l'),(3,'l'),(4,'o')]
761{-# INLINE indexed #-}
775{-# INLINE indexed #-}
762indexed :: Monad m => Stream m a -> Stream m (Int, a)
776indexed :: Monad m => Stream m a -> Stream m (Int, a)
763-- indexed = scanMaybe FL.indexing
777-- indexed = scanMaybe FL.indexing
@@ -776,6 +790,7 @@ indexed = fromStreamD . D.indexed . toStreamD
776-- >>> Stream.fold Fold.toList $ Stream.indexedR 10 $ Stream.fromList "hello"
790-- >>> Stream.fold Fold.toList $ Stream.indexedR 10 $ Stream.fromList "hello"
777-- [(10,'h'),(9,'e'),(8,'l'),(7,'l'),(6,'o')]
791-- [(10,'h'),(9,'e'),(8,'l'),(7,'l'),(6,'o')]
779{-# INLINE indexedR #-}
794{-# INLINE indexedR #-}
780indexedR :: Monad m => Int -> Stream m a -> Stream m (Int, a)
795indexedR :: Monad m => Int -> Stream m a -> Stream m (Int, a)
781-- indexedR n = scanMaybe (FL.indexingRev n)
796-- indexedR n = scanMaybe (FL.indexingRev n)
@@ -790,6 +805,7 @@ indexedR n = fromStreamD . D.indexedR n . toStreamD
791-- >>> elemIndices a = Stream.findIndices (== a)
806-- >>> elemIndices a = Stream.findIndices (== a)
793{-# INLINE elemIndices #-}
809{-# INLINE elemIndices #-}
794elemIndices :: (Monad m, Eq a) => a -> Stream m a -> Stream m Int
810elemIndices :: (Monad m, Eq a) => a -> Stream m a -> Stream m Int
795elemIndices a = findIndices (== a)
811elemIndices a = findIndices (== a)
@@ -844,6 +860,7 @@ rollingMap2 f m = fromStreamD $ D.rollingMap2 f $ toStreamD m
845-- >>> mapMaybe f = Stream.catMaybes . fmap f
861-- >>> mapMaybe f = Stream.catMaybes . fmap f
847{-# INLINE mapMaybe #-}
864{-# INLINE mapMaybe #-}
848mapMaybe :: Monad m => (a -> Maybe b) -> Stream m a -> Stream m b
865mapMaybe :: Monad m => (a -> Maybe b) -> Stream m a -> Stream m b
849mapMaybe f m = fromStreamD $ D.mapMaybe f $ toStreamD m
866mapMaybe f m = fromStreamD $ D.mapMaybe f $ toStreamD m
@@ -856,6 +873,7 @@ mapMaybe f m = fromStreamD $ D.mapMaybe f $ toStreamD m
857-- >>> mapM f = Stream.mapMaybeM (\x -> Just <$> f x)
874-- >>> mapM f = Stream.mapMaybeM (\x -> Just <$> f x)
859{-# INLINE_EARLY mapMaybeM #-}
877{-# INLINE_EARLY mapMaybeM #-}
860mapMaybeM :: Monad m
878mapMaybeM :: Monad m
861 => (a -> m (Maybe b)) -> Stream m a -> Stream m b
879 => (a -> m (Maybe b)) -> Stream m a -> Stream m b