@@ -335,6 +335,7 @@ module Streamly.Internal.Data.Fold.Type
335335 , foldl'
336336 , foldlM'
337337 , foldl1'
338+ , foldlM1'
338339 , foldt'
339340 , foldtM'
340341 , foldr'
@@ -550,6 +551,18 @@ foldl1' step = fmap toMaybe $ foldl' step1 Nothing'
550551 step1 Nothing' a = Just' a
551552 step1 (Just' x) a = Just' $ step x a
552553
554+-- | Like 'foldl1\'' but with a monadic step function.
555+--
556+-- /Pre-release/
557+{-# INLINE foldlM1' #-}
558+foldlM1' :: Monad m => (a -> a -> m a) -> Fold m a (Maybe a)
559+foldlM1' step = fmap toMaybe $ foldlM' step1 (return Nothing')
560+
561+ where
562+
563+ step1 Nothing' a = return $ Just' a
564+ step1 (Just' x) a = Just' <$> step x a
565+
553566------------------------------------------------------------------------------
554567-- Right fold constructors
555568------------------------------------------------------------------------------