@@ -17,6 +17,7 @@ module Streamly.Fold.Types
19 , lfilterM
19 , lfilterM
21 , ltakeWhile
22 , ltakeWhile
22 , lsessionsOf
23 , lsessionsOf
@@ -33,6 +34,7 @@ import Control.Monad (void)
33import Control.Monad.Catch (throwM)
34import Control.Monad.Catch (throwM)
34import Control.Monad.IO.Class (MonadIO(..))
35import Control.Monad.IO.Class (MonadIO(..))
35import Control.Monad.Trans.Control (control)
36import Control.Monad.Trans.Control (control)
37+import Data.Maybe (isJust, fromJust)
36import Data.Semigroup (Semigroup(..))
38import Data.Semigroup (Semigroup(..))
37import Streamly.Strict (Tuple'(..), Tuple3'(..), Either'(..))
39import Streamly.Strict (Tuple'(..), Tuple3'(..), Either'(..))
38import Streamly.SVar (MonadAsync)
40import Streamly.SVar (MonadAsync)
@@ -241,6 +243,12 @@ lfilterM f (Fold step begin done) = Fold step' begin done
241 use <- f a
243 use <- f a
242 if use then step x a else return x
244 if use then step x a else return x
246+-- | Transform a fold from a pure input to a 'Maybe' input, consuming only
248+{-# INLINE lcatMaybes #-}
249+lcatMaybes :: Monad m => Fold m a b -> Fold m (Maybe a) b
250+lcatMaybes = lfilter isJust . lmap fromJust
244-- | Take first 'n' elements from the stream and discard the rest.
252-- | Take first 'n' elements from the stream and discard the rest.
246-- @since 0.7.0
254-- @since 0.7.0