on master help sign in
Add "concat"
commitc05fe6039c6d71f3b5cbb79a3ef10d27366fd916 authorHarendra Kumar <harendra@composewell.com> dateThu 27 Feb 2020, 20:10 (7 years ago) parentfe8c6e7
1 file changed+17−3
src/Streamly/Internal/Prelude.hs+17−3
src/Streamly/Internal/Prelude.hs+17−3
@@ -448,9 +448,10 @@ module Streamly.Internal.Prelude
448448
449449 -- Flattening Nested Streams
450450 -- ** Folding Streams of Streams
451− , concatMapM
451+ , concat
452452 , concatM
453453 , concatMap
454+ , concatMapM
454455 -- XXX add stateful concatMapWith?
455456 , concatMapWith
456457 -- , bindWith
@@ -539,7 +540,7 @@ import Prelude
539540 notElem, maximum, minimum, head, last, tail, length, null,
540541 reverse, iterate, init, and, or, lookup, foldr1, (!!),
541542 scanl, scanl1, replicate, concatMap, span, splitAt, break,
542− repeat)
543+ repeat, concat)
543544
544545import qualified Data.Heap as H
545546import qualified Data.Map.Strict as Map
@@ -2567,6 +2568,17 @@ concatMapWith = K.concatMapBy
25672568concatMap ::(IsStream t, Monad m) => (a -> t m b) -> t m a -> t m b
25682569concatMap f m = fromStreamD $ D.concatMap (toStreamD . f) (toStreamD m)
25692570
2571+-- | Flatten a stream of streams to a single stream.
2572+--
2573+-- @
2574+-- concat = concatMap id
2575+-- @
2576+--
2577+-- /Internal/
2578+{-# INLINE concat #-}
2579+concat :: (IsStream t, Monad m) => t m (t m a) -> t m a
2580+concat = concatMap id
2581+
25702582-- | Append the outputs of two streams, yielding all the elements from the
25712583-- first stream and then yielding all the elements from the second stream.
25722584--
@@ -2705,11 +2717,13 @@ concatMapM f m = fromStreamD $ D.concatMapM (fmap toStreamD . f) (toStreamD m)
27052717-- | Given a stream value in the underlying monad, lift and join the underlying
27062718-- monad with the stream monad.
27072719--
2720+-- Compare with 'concat' and 'sequence'.
2721+--
27082722-- /Internal/
27092723--
27102724{-# INLINE concatM #-}
27112725concatM :: (IsStream t, Monad m) => m (t m a) -> t m a
2712−concatM generator = concatMapM (\() -> generator) (K.yield ())
2726+concatM generator = concatMapM (\() -> generator) (yield ())
27132727
27142728-- | Like 'concatMap' but uses an 'Unfold' for stream generation. Unlike
27152729-- 'concatMap' this can fuse the 'Unfold' code with the inner loop and