@@ -495,6 +495,8 @@ foldr f = foldrM (\a b -> return (f a b))
496-- | Right fold, for non-empty streams, using first element as the starting
496-- | Right fold, for non-empty streams, using first element as the starting
497-- value. Returns 'Nothing' if the stream is empty.
497-- value. Returns 'Nothing' if the stream is empty.
498{-# INLINE foldr1 #-}
500{-# INLINE foldr1 #-}
499foldr1 :: Monad m => (a -> a -> a) -> SerialT m a -> m (Maybe a)
501foldr1 :: Monad m => (a -> a -> a) -> SerialT m a -> m (Maybe a)
500foldr1 = K.foldr1
502foldr1 = K.foldr1
@@ -524,6 +526,8 @@ foldl' step begin m = S.foldl' step begin $ toStreamS m
525-- | Strict left fold, for non-empty streams, using first element as the
527-- | Strict left fold, for non-empty streams, using first element as the
526-- starting value. Returns 'Nothing' if the stream is empty.
528-- starting value. Returns 'Nothing' if the stream is empty.
527foldl1' :: Monad m => (a -> a -> a) -> SerialT m a -> m (Maybe a)
531foldl1' :: Monad m => (a -> a -> a) -> SerialT m a -> m (Maybe a)
528foldl1' step m = do
532foldl1' step m = do
529 r <- uncons m
533 r <- uncons m
@@ -578,6 +582,8 @@ tail :: (IsStream t, Monad m) => SerialT m a -> m (Maybe (t m a))
578tail m = K.tail (K.adapt m)
582tail m = K.tail (K.adapt m)
580-- | Extract all but the last element of the stream, if any.
584-- | Extract all but the last element of the stream, if any.
581{-# INLINE init #-}
587{-# INLINE init #-}
582init :: (IsStream t, Monad m) => SerialT m a -> m (Maybe (t m a))
588init :: (IsStream t, Monad m) => SerialT m a -> m (Maybe (t m a))
583init m = K.init (K.adapt m)
589init m = K.init (K.adapt m)
@@ -625,11 +631,15 @@ any :: Monad m => (a -> Bool) -> SerialT m a -> m Bool
625any p m = S.any p (toStreamS m)
631any p m = S.any p (toStreamS m)
627-- | Determines if all elements of a boolean stream are True.
633-- | Determines if all elements of a boolean stream are True.
628{-# INLINE and #-}
636{-# INLINE and #-}
629and :: Monad m => SerialT m Bool -> m Bool
637and :: Monad m => SerialT m Bool -> m Bool
630and = all (==True)
638and = all (==True)
632-- | Determines wheter at least one element of a boolean stream is True.
640-- | Determines wheter at least one element of a boolean stream is True.
633{-# INLINE or #-}
643{-# INLINE or #-}
634or :: Monad m => SerialT m Bool -> m Bool
644or :: Monad m => SerialT m Bool -> m Bool
635or = any (==True)
645or = any (==True)
@@ -663,34 +673,46 @@ maximum :: (Monad m, Ord a) => SerialT m a -> m (Maybe a)
663maximum m = S.maximum (toStreamS m)
673maximum m = S.maximum (toStreamS m)
665-- | Looks the given key up, treating the given stream as an association list.
675-- | Looks the given key up, treating the given stream as an association list.
666{-# INLINE lookup #-}
678{-# INLINE lookup #-}
667lookup :: (Monad m, Eq a) => a -> SerialT m (a, b) -> m (Maybe b)
679lookup :: (Monad m, Eq a) => a -> SerialT m (a, b) -> m (Maybe b)
668lookup = K.lookup
680lookup = K.lookup
670-- | Returns the first element of the stream satisfying the given predicate,
682-- | Returns the first element of the stream satisfying the given predicate,
671-- if any.
683-- if any.
672{-# INLINE find #-}
686{-# INLINE find #-}
673find :: Monad m => (a -> Bool) -> SerialT m a -> m (Maybe a)
687find :: Monad m => (a -> Bool) -> SerialT m a -> m (Maybe a)
674find = K.find
688find = K.find
676-- | Finds all the indices of elements satisfying the given predicate.
690-- | Finds all the indices of elements satisfying the given predicate.
677{-# INLINE findIndices #-}
693{-# INLINE findIndices #-}
678findIndices :: IsStream t => (a -> Bool) -> t m a -> t m Int
694findIndices :: IsStream t => (a -> Bool) -> t m a -> t m Int
679findIndices = K.findIndices
695findIndices = K.findIndices
681-- | Gives the index of the first stream element satisfying the given
697-- | Gives the index of the first stream element satisfying the given
682-- preficate.
698-- preficate.
683{-# INLINE findIndex #-}
701{-# INLINE findIndex #-}
684findIndex :: Monad m => (a -> Bool) -> SerialT m a -> m (Maybe Int)
702findIndex :: Monad m => (a -> Bool) -> SerialT m a -> m (Maybe Int)
685findIndex p = head . findIndices p
703findIndex p = head . findIndices p
687-- | Finds the index of all elements in the stream which are equal to the
705-- | Finds the index of all elements in the stream which are equal to the
689{-# INLINE elemIndices #-}
709{-# INLINE elemIndices #-}
690elemIndices :: (IsStream t, Eq a) => a -> t m a -> t m Int
710elemIndices :: (IsStream t, Eq a) => a -> t m a -> t m Int
691elemIndices a = findIndices (==a)
711elemIndices a = findIndices (==a)
693-- | Gives the first index of an element in the stream, which equals the given.
713-- | Gives the first index of an element in the stream, which equals the given.
694{-# INLINE elemIndex #-}
716{-# INLINE elemIndex #-}
695elemIndex :: (Monad m, Eq a) => a -> SerialT m a -> m (Maybe Int)
717elemIndex :: (Monad m, Eq a) => a -> SerialT m a -> m (Maybe Int)
696elemIndex a = findIndex (==a)
718elemIndex a = findIndex (==a)
@@ -927,6 +949,8 @@ reverse m = fromStream $ go K.nil (toStream m)
928-- | Generate a stream by performing the monadic action inbetween all elements
950-- | Generate a stream by performing the monadic action inbetween all elements
929-- of the given stream.
951-- of the given stream.
930{-# INLINE intersperseM #-}
954{-# INLINE intersperseM #-}
931intersperseM :: (IsStream t, MonadAsync m) => m a -> t m a -> t m a
955intersperseM :: (IsStream t, MonadAsync m) => m a -> t m a -> t m a
932intersperseM = K.intersperseM
956intersperseM = K.intersperseM