on master help sign in
Rename concatChunks, compactChunks to concat, compact
commitc3b8dd41fb8c565208931c88cafb96c6b45137c9 authorHarendra Kumar <harendra@composewell.com> dateMon 1 Jan 2024, 09:45 (3 years ago) parentfa14d0e
6 files changed+79−79
core/src/Streamly/Internal/Data/Array/Type.hs+15−15 core/src/Streamly/Internal/Data/MutArray.hs+6−6 core/src/Streamly/Internal/Data/MutArray/Stream.hs+4−4 core/src/Streamly/Internal/Data/MutArray/Type.hs+52−52 core/src/Streamly/Internal/Data/Stream/Transform.hs+1−1 src/Streamly/Internal/Data/Stream/IsStream/Common.hs+1−1
core/src/Streamly/Internal/Data/Array/Type.hs+15−15
@@ -117,8 +117,8 @@ module Streamly.Internal.Data.Array.Type
117117
118118 -- *** Concat
119119 -- | Append the arrays in a stream to form a stream of elements.
120− , concatChunks
121− , concatChunksRev
120+ , concat
121+ , concatRev
122122
123123 -- *** Compact
124124 -- | Append the arrays in a stream to form a stream of larger arrays.
@@ -163,7 +163,7 @@ import Streamly.Internal.Data.Unbox (Unbox(..))
163163import Streamly.Internal.Data.Unfold.Type (Unfold(..))
164164import Text.Read (readPrec)
165165
166−import Prelude hiding (Foldable(..), read, unlines, splitAt)
166+import Prelude hiding (Foldable(..), concat, read, unlines, splitAt)
167167
168168import qualified GHC.Exts as Exts
169169import qualified Streamly.Internal.Data.MutArray.Type as MA
@@ -450,35 +450,35 @@ pinnedChunksOf n str = D.map unsafeFreeze $ MA.pinnedChunksOf n str
450450
451451-- | Convert a stream of arrays into a stream of their elements.
452452--
453−-- >>> concatChunks = Stream.unfoldMany Array.reader
453+-- >>> concat = Stream.unfoldMany Array.reader
454454--
455−{-# INLINE_NORMAL concatChunks #-}
456−concatChunks :: (MonadIO m, Unbox a) => Stream m (Array a) -> Stream m a
455+{-# INLINE_NORMAL concat #-}
456+concat :: (MonadIO m, Unbox a) => Stream m (Array a) -> Stream m a
457457-- XXX this requires MonadIO whereas the unfoldMany version does not
458−concatChunks = MA.concatChunks . D.map unsafeThaw
459−-- concatChunks = D.unfoldMany reader
458+concat = MA.concat . D.map unsafeThaw
459+-- concat = D.unfoldMany reader
460460
461461{-# DEPRECATED flattenArrays "Please use \"unfoldMany reader\" instead." #-}
462462flattenArrays :: forall m a. (MonadIO m, Unbox a)
463463 => D.Stream m (Array a) -> D.Stream m a
464−flattenArrays = concatChunks
464+flattenArrays = concat
465465
466466-- | Convert a stream of arrays into a stream of their elements reversing the
467467-- contents of each array before flattening.
468468--
469−-- >>> concatChunksRev = Stream.unfoldMany Array.readerRev
469+-- >>> concatRev = Stream.unfoldMany Array.readerRev
470470--
471−{-# INLINE_NORMAL concatChunksRev #-}
472−concatChunksRev :: forall m a. (MonadIO m, Unbox a)
471+{-# INLINE_NORMAL concatRev #-}
472+concatRev :: forall m a. (MonadIO m, Unbox a)
473473 => D.Stream m (Array a) -> D.Stream m a
474474-- XXX this requires MonadIO whereas the unfoldMany version does not
475−concatChunksRev = MA.concatChunksRev . D.map unsafeThaw
476−-- concatChunksRev = D.unfoldMany readerRev
475+concatRev = MA.concatRev . D.map unsafeThaw
476+-- concatRev = D.unfoldMany readerRev
477477
478478{-# DEPRECATED flattenArraysRev "Please use \"unfoldMany readerRev\" instead." #-}
479479flattenArraysRev :: forall m a. (MonadIO m, Unbox a)
480480 => D.Stream m (Array a) -> D.Stream m a
481−flattenArraysRev = concatChunksRev
481+flattenArraysRev = concatRev
482482
483483-- Drops the separator byte
484484{-# INLINE breakOn #-}
core/src/Streamly/Internal/Data/MutArray.hs+6−6
@@ -13,7 +13,7 @@ module Streamly.Internal.Data.MutArray
1313 -- * MutArray module
1414 , sliceIndexerFromLen
1515 , slicerFromLen
16− , compactChunksLE
16+ , compactLE
1717 -- * Unboxed IORef
1818 , module Streamly.Internal.Data.IORef.Unboxed
1919
@@ -83,10 +83,10 @@ getSlicesFromLen :: forall m a. (Monad m, Unbox a)
8383 -> Unfold m (MutArray a) (MutArray a)
8484getSlicesFromLen = slicerFromLen
8585
86−-- | Scan @compactChunksLE n@ coalesces adjacent arrays in the input stream
86+-- | Scan @compactLE n@ coalesces adjacent arrays in the input stream
8787-- only if the combined size would be less than or equal to n.
88−{-# INLINE compactChunksLE #-}
89−compactChunksLE :: (MonadIO m, Unbox a) =>
88+{-# INLINE compactLE #-}
89+compactLE :: (MonadIO m, Unbox a) =>
9090 Int -> Stream m (MutArray a) -> Stream m (MutArray a)
91−-- compactLE n = Stream.catRights . Stream.parseManyD (pCompactChunksLE n)
92−compactChunksLE = rCompactChunksLE
91+-- compactLE n = Stream.catRights . Stream.parseManyD (pCompactLE n)
92+compactLE = rCompactLE
core/src/Streamly/Internal/Data/MutArray/Stream.hs+4−4
@@ -69,7 +69,7 @@ import qualified Streamly.Internal.Data.Stream as D
6969{-# INLINE packArraysChunksOf #-}
7070packArraysChunksOf :: (MonadIO m, Unbox a)
7171 => Int -> D.Stream m (MutArray a) -> D.Stream m (MutArray a)
72−packArraysChunksOf = MArray.compactChunksLE
72+packArraysChunksOf = MArray.compactLE
7373
7474-- XXX Remove this once compactLEFold is implemented
7575-- lpackArraysChunksOf = Fold.many compactLEFold
@@ -77,7 +77,7 @@ packArraysChunksOf = MArray.compactChunksLE
7777{-# INLINE lpackArraysChunksOf #-}
7878lpackArraysChunksOf :: (MonadIO m, Unbox a)
7979 => Int -> Fold m (MutArray a) () -> Fold m (MutArray a) ()
80−lpackArraysChunksOf = MArray.lCompactChunksGE
80+lpackArraysChunksOf = MArray.lCompactGE
8181
8282-- XXX Same as compactLE, to be removed once that is implemented.
8383--
@@ -101,7 +101,7 @@ compact = packArraysChunksOf
101101compactLEParserD ::
102102 forall m a. (MonadIO m, Unbox a)
103103 => Int -> ParserD.Parser (MutArray a) m (MutArray a)
104−compactLEParserD = MArray.pCompactChunksLE
104+compactLEParserD = MArray.pCompactLE
105105
106106-- | Coalesce adjacent arrays in incoming stream to form bigger arrays of a
107107-- minimum specified size. Note that if all the arrays in the stream together
@@ -114,7 +114,7 @@ compactLEParserD = MArray.pCompactChunksLE
114114compactGEFold ::
115115 forall m a. (MonadIO m, Unbox a)
116116 => Int -> FL.Fold m (MutArray a) (MutArray a)
117−compactGEFold = MArray.fCompactChunksGE
117+compactGEFold = MArray.fCompactGE
118118
119119-- | Coalesce adjacent arrays in incoming stream to form bigger arrays of a
120120-- maximum specified size in bytes.
core/src/Streamly/Internal/Data/MutArray/Type.hs+52−52
@@ -234,18 +234,18 @@ module Streamly.Internal.Data.MutArray.Type
234234
235235 -- *** Concat
236236 -- | Append the arrays in a stream to form a stream of elements.
237− , concatChunks
238− , concatChunksRev
237+ , concat
238+ , concatRev
239239
240240 -- *** Compact
241241 -- | Append the arrays in a stream to form a stream of larger arrays.
242242 , SpliceState (..)
243− , pCompactChunksLE
244− , rCompactChunksLE
245− , fCompactChunksGE
246− , lCompactChunksGE
247− , compactChunksGE
248− , compactChunksEQ
243+ , pCompactLE
244+ , rCompactLE
245+ , fCompactGE
246+ , lCompactGE
247+ , compactGE
248+ , compactEQ
249249
250250 -- ** Utilities
251251 , roundUpToPower2
@@ -318,7 +318,7 @@ import qualified Streamly.Internal.Data.StreamK.Type as K
318318import qualified Prelude
319319
320320import Prelude hiding
321− (Foldable(..), read, unlines, splitAt, reverse, truncate)
321+ (Foldable(..), concat, read, unlines, splitAt, reverse, truncate)
322322
323323#include "DocTestDataMutArray.hs"
324324
@@ -851,7 +851,7 @@ reallocWith label capSizer minIncrBytes arr = do
851851 where
852852
853853 badSize newSize =
854− concat
854+ Prelude.concat
855855 [ label
856856 , ": new array size (in bytes) is less than required size "
857857 , show newSize
@@ -1465,14 +1465,14 @@ data FlattenState s contents a =
14651465
14661466-- | Use the "reader" unfold instead.
14671467--
1468−-- @concatChunks = unfoldMany reader@
1468+-- @concat = unfoldMany reader@
14691469--
14701470-- We can try this if there are any fusion issues in the unfold.
14711471--
1472−{-# INLINE_NORMAL concatChunks #-}
1473−concatChunks :: forall m a. (MonadIO m, Unbox a)
1472+{-# INLINE_NORMAL concat #-}
1473+concat :: forall m a. (MonadIO m, Unbox a)
14741474 => D.Stream m (MutArray a) -> D.Stream m a
1475−concatChunks (D.Stream step state) = D.Stream step' (OuterLoop state)
1475+concat (D.Stream step state) = D.Stream step' (OuterLoop state)
14761476
14771477 where
14781478
@@ -1495,18 +1495,18 @@ concatChunks (D.Stream step state) = D.Stream step' (OuterLoop state)
14951495{-# DEPRECATED flattenArrays "Please use \"unfoldMany reader\" instead." #-}
14961496flattenArrays :: forall m a. (MonadIO m, Unbox a)
14971497 => D.Stream m (MutArray a) -> D.Stream m a
1498−flattenArrays = concatChunks
1498+flattenArrays = concat
14991499
15001500-- | Use the "readerRev" unfold instead.
15011501--
1502−-- @concatChunks = unfoldMany readerRev@
1502+-- @concat = unfoldMany readerRev@
15031503--
15041504-- We can try this if there are any fusion issues in the unfold.
15051505--
1506−{-# INLINE_NORMAL concatChunksRev #-}
1507−concatChunksRev :: forall m a. (MonadIO m, Unbox a)
1506+{-# INLINE_NORMAL concatRev #-}
1507+concatRev :: forall m a. (MonadIO m, Unbox a)
15081508 => D.Stream m (MutArray a) -> D.Stream m a
1509−concatChunksRev (D.Stream step state) = D.Stream step' (OuterLoop state)
1509+concatRev (D.Stream step state) = D.Stream step' (OuterLoop state)
15101510
15111511 where
15121512
@@ -1531,7 +1531,7 @@ concatChunksRev (D.Stream step state) = D.Stream step' (OuterLoop state)
15311531{-# DEPRECATED flattenArraysRev "Please use \"unfoldMany readerRev\" instead." #-}
15321532flattenArraysRev :: forall m a. (MonadIO m, Unbox a)
15331533 => D.Stream m (MutArray a) -> D.Stream m a
1534−flattenArraysRev = concatChunksRev
1534+flattenArraysRev = concatRev
15351535
15361536-------------------------------------------------------------------------------
15371537-- Unfolds
@@ -2625,21 +2625,21 @@ byteEq arr1 arr2 = fmap (EQ ==) $ byteCmp arr1 arr2
26252625-- Compact
26262626-------------------------------------------------------------------------------
26272627
2628−-- | Parser @pCompactChunksLE n@ coalesces adjacent arrays in the input stream
2628+-- | Parser @pCompactLE n@ coalesces adjacent arrays in the input stream
26292629-- only if the combined size would be less than or equal to n.
26302630--
26312631-- /Internal/
2632−{-# INLINE_NORMAL pCompactChunksLE #-}
2633−pCompactChunksLE ::
2632+{-# INLINE_NORMAL pCompactLE #-}
2633+pCompactLE ::
26342634 forall m a. (MonadIO m, Unbox a)
26352635 => Int -> Parser (MutArray a) m (MutArray a)
2636−pCompactChunksLE n = Parser step initial extract
2636+pCompactLE n = Parser step initial extract
26372637
26382638 where
26392639
26402640 nBytes = n * SIZE_OF(a)
26412641
2642− functionName = "Streamly.Internal.Data.MutArray.pCompactChunksLE"
2642+ functionName = "Streamly.Internal.Data.MutArray.pCompactLE"
26432643
26442644 initial =
26452645 return
@@ -2683,19 +2683,19 @@ data SpliceState s arr
26832683-- immutable array never has additional space so a new array is allocated
26842684-- instead of mutating it.
26852685
2686−-- | Scan @rCompactChunksLE n@ coalesces adjacent arrays in the input stream
2686+-- | Scan @rCompactLE n@ coalesces adjacent arrays in the input stream
26872687-- only if the combined size would be less than or equal to n.
26882688--
26892689-- /Internal/
2690−{-# INLINE_NORMAL rCompactChunksLE #-}
2691−rCompactChunksLE :: (MonadIO m, Unbox a)
2690+{-# INLINE_NORMAL rCompactLE #-}
2691+rCompactLE :: (MonadIO m, Unbox a)
26922692 => Int -> D.Stream m (MutArray a) -> D.Stream m (MutArray a)
2693−rCompactChunksLE n (D.Stream step state) =
2693+rCompactLE n (D.Stream step state) =
26942694 D.Stream step' (SpliceInitial state)
26952695
26962696 where
26972697
2698− functionName = "Streamly.Internal.Data.MutArray.rCompactChunksLE"
2698+ functionName = "Streamly.Internal.Data.MutArray.rCompactLE"
26992699
27002700 {-# INLINE_LATE step' #-}
27012701 step' gst (SpliceInitial st) = do
@@ -2735,20 +2735,20 @@ rCompactChunksLE n (D.Stream step state) =
27352735
27362736 step' _ (SpliceYielding arr next) = return $ D.Yield arr next
27372737
2738−-- | Fold @fCompactChunksGE n@ coalesces adjacent arrays in the input stream
2738+-- | Fold @fCompactGE n@ coalesces adjacent arrays in the input stream
27392739-- until the size becomes greater than or equal to n.
27402740--
2741−{-# INLINE_NORMAL fCompactChunksGE #-}
2742−fCompactChunksGE ::
2741+{-# INLINE_NORMAL fCompactGE #-}
2742+fCompactGE ::
27432743 forall m a. (MonadIO m, Unbox a)
27442744 => Int -> FL.Fold m (MutArray a) (MutArray a)
2745−fCompactChunksGE n = Fold step initial extract extract
2745+fCompactGE n = Fold step initial extract extract
27462746
27472747 where
27482748
27492749 nBytes = n * SIZE_OF(a)
27502750
2751− functionName = "Streamly.Internal.Data.MutArray.fCompactChunksGE"
2751+ functionName = "Streamly.Internal.Data.MutArray.fCompactGE"
27522752
27532753 initial =
27542754 return
@@ -2779,20 +2779,20 @@ fCompactChunksGE n = Fold step initial extract extract
27792779 extract Nothing = return nil
27802780 extract (Just buf) = return buf
27812781
2782−-- | Like 'compactChunksGE' but for transforming folds instead of stream.
2782+-- | Like 'compactGE' but for transforming folds instead of stream.
27832783--
2784−-- >>> lCompactChunksGE n = Fold.many (MutArray.fCompactChunksGE n)
2784+-- >>> lCompactGE n = Fold.many (MutArray.fCompactGE n)
27852785--
2786−{-# INLINE_NORMAL lCompactChunksGE #-}
2787−lCompactChunksGE :: (MonadIO m, Unbox a)
2786+{-# INLINE_NORMAL lCompactGE #-}
2787+lCompactGE :: (MonadIO m, Unbox a)
27882788 => Int -> Fold m (MutArray a) () -> Fold m (MutArray a) ()
2789−-- lCompactChunksGE n = Fold.many (fCompactChunksGE n)
2790−lCompactChunksGE n (Fold step1 initial1 _ final1) =
2789+-- lCompactGE n = Fold.many (fCompactGE n)
2790+lCompactGE n (Fold step1 initial1 _ final1) =
27912791 Fold step initial extract final
27922792
27932793 where
27942794
2795− functionName = "Streamly.Internal.Data.MutArray.lCompactChunksGE"
2795+ functionName = "Streamly.Internal.Data.MutArray.lCompactGE"
27962796
27972797 initial = do
27982798 when (n <= 0) $
@@ -2841,7 +2841,7 @@ lCompactChunksGE n (Fold step1 initial1 _ final1) =
28412841 --
28422842 -- extract forces the pending buffer to be sent to the fold which is not
28432843 -- what we want.
2844− extract _ = error "lCompactChunksGE: not designed for scanning"
2844+ extract _ = error "lCompactGE: not designed for scanning"
28452845
28462846 final (Tuple' Nothing r1) = final1 r1
28472847 final (Tuple' (Just buf) r1) = do
@@ -2850,25 +2850,25 @@ lCompactChunksGE n (Fold step1 initial1 _ final1) =
28502850 FL.Partial rr -> final1 rr
28512851 FL.Done _ -> return ()
28522852
2853−-- | @compactChunksGE n stream@ coalesces adjacent arrays in the @stream@ until
2853+-- | @compactGE n stream@ coalesces adjacent arrays in the @stream@ until
28542854-- the size becomes greater than or equal to @n@.
28552855--
2856−-- >>> compactChunksGE n = Stream.foldMany (MutArray.fCompactChunksGE n)
2856+-- >>> compactGE n = Stream.foldMany (MutArray.fCompactGE n)
28572857--
2858−{-# INLINE compactChunksGE #-}
2859−compactChunksGE ::
2858+{-# INLINE compactGE #-}
2859+compactGE ::
28602860 (MonadIO m, Unbox a)
28612861 => Int -> Stream m (MutArray a) -> Stream m (MutArray a)
2862−compactChunksGE n = D.foldMany (fCompactChunksGE n)
2862+compactGE n = D.foldMany (fCompactGE n)
28632863
2864−-- | 'compactChunksEQ n' coalesces adajacent arrays in the input stream to
2864+-- | 'compactEQ n' coalesces adajacent arrays in the input stream to
28652865-- arrays of exact size @n@.
28662866--
28672867-- /Unimplemented/
2868−{-# INLINE compactChunksEQ #-}
2869−compactChunksEQ :: -- (MonadIO m, Unbox a) =>
2868+{-# INLINE compactEQ #-}
2869+compactEQ :: -- (MonadIO m, Unbox a) =>
28702870 Int -> Stream m (MutArray a) -> Stream m (MutArray a)
2871−compactChunksEQ _n = undefined -- D.parseManyD (pCompactChunksEQ n)
2871+compactEQ _n = undefined -- D.parseManyD (pCompactEQ n)
28722872
28732873-------------------------------------------------------------------------------
28742874-- In-place mutation algorithms
core/src/Streamly/Internal/Data/Stream/Transform.hs+1−1
@@ -1537,7 +1537,7 @@ reverse m = Stream step Nothing
15371537{-# INLINE reverseUnbox #-}
15381538reverseUnbox :: (MonadIO m, Unbox a) => Stream m a -> Stream m a
15391539reverseUnbox =
1540− A.concatChunksRev -- unfoldMany A.readerRev
1540+ A.concatRev -- unfoldMany A.readerRev
15411541 . fromStreamK
15421542 . K.reverse
15431543 . toStreamK
src/Streamly/Internal/Data/Stream/IsStream/Common.hs+1−1
@@ -529,7 +529,7 @@ reverse' :: (IsStream t, MonadIO m, Unbox a) => t m a -> t m a
529529-- reverse' s = fromStreamD $ D.reverse' $ toStreamD s
530530reverse' =
531531 fromStreamD
532− . A.concatChunksRev -- unfoldMany A.readerRev
532+ . A.concatRev -- unfoldMany A.readerRev
533533 . D.fromStreamK
534534 . K.reverse
535535 . D.toStreamK