Skip to content

Commit

Permalink
Split IsStream.Nesting into Expand and Reduce
Browse files Browse the repository at this point in the history
  • Loading branch information
harendra-kumar committed Mar 18, 2021
1 parent ee691b6 commit 8be2c1c
Show file tree
Hide file tree
Showing 7 changed files with 913 additions and 813 deletions.
6 changes: 4 additions & 2 deletions src/Streamly/Internal/Data/Stream/IsStream.hs
Expand Up @@ -15,7 +15,8 @@ module Streamly.Internal.Data.Stream.IsStream
, module Streamly.Internal.Data.Stream.IsStream.Generate
, module Streamly.Internal.Data.Stream.IsStream.Eliminate
, module Streamly.Internal.Data.Stream.IsStream.Transform
, module Streamly.Internal.Data.Stream.IsStream.Nesting
, module Streamly.Internal.Data.Stream.IsStream.Expand
, module Streamly.Internal.Data.Stream.IsStream.Reduce
, module Streamly.Internal.Data.Stream.IsStream.Exception
, module Streamly.Internal.Data.Stream.IsStream.Lift
, module Streamly.Internal.Data.Stream.IsStream.Top
Expand All @@ -27,6 +28,7 @@ import Streamly.Internal.Data.Stream.IsStream.Eliminate
import Streamly.Internal.Data.Stream.IsStream.Exception
import Streamly.Internal.Data.Stream.IsStream.Generate
import Streamly.Internal.Data.Stream.IsStream.Lift
import Streamly.Internal.Data.Stream.IsStream.Nesting
import Streamly.Internal.Data.Stream.IsStream.Expand
import Streamly.Internal.Data.Stream.IsStream.Reduce
import Streamly.Internal.Data.Stream.IsStream.Transform
import Streamly.Internal.Data.Stream.IsStream.Types
18 changes: 17 additions & 1 deletion src/Streamly/Internal/Data/Stream/IsStream/Common.hs
Expand Up @@ -42,6 +42,7 @@ module Streamly.Internal.Data.Stream.IsStream.Common
-- * Nesting
, concatM
, concatMapM
, concatMap
, splitOnSeq
)
where
Expand Down Expand Up @@ -72,7 +73,7 @@ import qualified Streamly.Internal.Data.Stream.StreamK as S
import qualified Streamly.Internal.Data.Stream.StreamD as S
#endif

import Prelude hiding (take, takeWhile, drop, reverse)
import Prelude hiding (take, takeWhile, drop, reverse, concatMap)

--
-- $setup
Expand Down Expand Up @@ -452,6 +453,21 @@ reverse' s = fromStreamD $ D.reverse' $ toStreamD s
concatMapM :: (IsStream t, Monad m) => (a -> m (t m b)) -> t m a -> t m b
concatMapM f m = fromStreamD $ D.concatMapM (fmap toStreamD . f) (toStreamD m)

-- | Map a stream producing function on each element of the stream and then
-- flatten the results into a single stream.
--
-- @
-- concatMap f = 'concatMapM' (return . f)
-- concatMap = 'concatMapWith' 'Serial.serial'
-- concatMap f = 'concat . map f'
-- concatMap f = 'concatUnfold' (UF.lmap f UF.fromStream)
-- @
--
-- @since 0.6.0
{-# INLINE concatMap #-}
concatMap ::(IsStream t, Monad m) => (a -> t m b) -> t m a -> t m b
concatMap f m = fromStreamD $ D.concatMap (toStreamD . f) (toStreamD m)

-- | Given a stream value in the underlying monad, lift and join the underlying
-- monad with the stream monad.
--
Expand Down

0 comments on commit 8be2c1c

Please sign in to comment.