on master help sign in
expose lcatMaybes via the Streamly.Internal module
a3ee4a8Harendra Kumar
src/Streamly/Fold/Types.hs+8
@@ -17,6 +17,7 @@ module Streamly.Fold.Types
17 , lmapM
17 , lmapM
18 , lfilter
18 , lfilter
19 , lfilterM
19 , lfilterM
20+ , lcatMaybes
20 , ltake
21 , ltake
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
243
245
246+-- | Transform a fold from a pure input to a 'Maybe' input, consuming only
247+-- 'Just' values.
248+{-# INLINE lcatMaybes #-}
249+lcatMaybes :: Monad m => Fold m a b -> Fold m (Maybe a) b
250+lcatMaybes = lfilter isJust . lmap fromJust
251+
244-- | Take first 'n' elements from the stream and discard the rest.
252-- | Take first 'n' elements from the stream and discard the rest.
245--
253--
246-- @since 0.7.0
254-- @since 0.7.0
src/Streamly/Internal.hs+3−1
@@ -28,6 +28,7 @@ module Streamly.Internal
28 , lmapM
28 , lmapM
29 , lfilter
29 , lfilter
30 , lfilterM
30 , lfilterM
31+ , lcatMaybes
31 , ltake
32 , ltake
32 , ltakeWhile
33 , ltakeWhile
33 , lsessionsOf
34 , lsessionsOf
@@ -36,6 +37,7 @@ module Streamly.Internal
36 )
37 )
37where
38where
38
39
39−import Streamly.Fold.Types
40import Streamly.Streams.Combinators (inspectMode)
40import Streamly.Streams.Combinators (inspectMode)
41import Streamly.Streams.Parallel (tapAsync)
41import Streamly.Streams.Parallel (tapAsync)
42+
43+import Streamly.Fold.Types
src/Streamly/Prelude.hs+1−7
@@ -2674,12 +2674,6 @@ chunksOf
2674 => Int -> Fold m a b -> t m a -> t m b
2674 => Int -> Fold m a b -> t m a -> t m b
2675chunksOf n f m = D.fromStreamD $ D.groupsOf n f (D.toStreamD m)
2675chunksOf n f m = D.fromStreamD $ D.groupsOf n f (D.toStreamD m)
2676
2676
2677−-- | Transform a fold from a pure input to a 'Maybe' input, consuming only
2678−-- 'Just' values.
2679−{-# INLINE lcatMaybes #-}
2680−lcatMaybes :: Monad m => Fold m a b -> Fold m (Maybe a) b
2681−lcatMaybes = FL.lfilter isJust . FL.lmap fromJust
2682−
2683-- XXX we can implement this by repeatedly applying the 'lrunFor' fold.
2677-- XXX we can implement this by repeatedly applying the 'lrunFor' fold.
2684-- XXX add this example after fixing the serial stream rate control
2678-- XXX add this example after fixing the serial stream rate control
2685-- >>> S.toList $ S.take 5 $ sessionsOf 1 FL.sum $ constRate 2 $ S.enumerateFrom 1
2679-- >>> S.toList $ S.take 5 $ sessionsOf 1 FL.sum $ constRate 2 $ S.enumerateFrom 1
@@ -2694,7 +2688,7 @@ sessionsOf
2694 :: (IsStream t, MonadAsync m)
2688 :: (IsStream t, MonadAsync m)
2695 => Double -> Fold m a b -> t m a -> t m b
2689 => Double -> Fold m a b -> t m a -> t m b
2696sessionsOf n f xs =
2690sessionsOf n f xs =
2697− splitBySuffix isNothing (lcatMaybes f)
2691+ splitBySuffix isNothing (FL.lcatMaybes f)
2698 (intersperseByTime n (return Nothing) (Serial.map Just xs))
2692 (intersperseByTime n (return Nothing) (Serial.map Just xs))
2699
2693
2700------------------------------------------------------------------------------
2694------------------------------------------------------------------------------