@@ -78,9 +78,6 @@ module Streamly.Internal.Prelude
81− -- ** Composable Left Folds
84 -- ** Full Folds
81 -- ** Full Folds
86 -- -- ** To Summary (Full Folds)
83 -- -- ** To Summary (Full Folds)
@@ -97,14 +94,6 @@ module Streamly.Internal.Prelude
97 , minimumBy
94 , minimumBy
100− , toListRev -- experimental
106− -- -- ** To Containers (Full Folds)
109 -- ** Partial Folds
98 -- ** Partial Folds
@@ -130,6 +119,18 @@ module Streamly.Internal.Prelude
128+ -- ** Composable Left Folds
131+ , toStream -- XXX rename to write?
132+ , toStreamRev -- XXX rename to writeRev?
133 -- * Transformation
134 -- * Transformation
134 , transform
135 , transform
@@ -397,7 +398,7 @@ import Control.Monad (void)
397import Control.Monad.Catch (MonadCatch)
398import Control.Monad.Catch (MonadCatch)
398import Control.Monad.IO.Class (MonadIO(..))
399import Control.Monad.IO.Class (MonadIO(..))
399import Control.Monad.Trans (MonadTrans(..))
400import Control.Monad.Trans (MonadTrans(..))
400−import Data.Functor.Identity (Identity)
401+import Data.Functor.Identity (Identity (..))
401import Data.Heap (Entry(..))
402import Data.Heap (Entry(..))
402import Data.Maybe (isJust, fromJust, isNothing)
403import Data.Maybe (isJust, fromJust, isNothing)
403import Foreign.Storable (Storable)
404import Foreign.Storable (Storable)
@@ -1380,7 +1381,7 @@ toList = P.toList
1380-- /Warning!/ working on large lists accumulated as buffers in memory could be
1381-- /Warning!/ working on large lists accumulated as buffers in memory could be
1381-- very inefficient, consider using "Streamly.Array" instead.
1382-- very inefficient, consider using "Streamly.Array" instead.
1383−-- @since 0.7.0
1384+-- /Internal/
1384{-# INLINE toListRev #-}
1385{-# INLINE toListRev #-}
1385toListRev :: Monad m => SerialT m a -> m [a]
1386toListRev :: Monad m => SerialT m a -> m [a]
1386toListRev = D.toListRev . toStreamD
1387toListRev = D.toListRev . toStreamD
@@ -1404,12 +1405,15 @@ toHandle h m = go m
1404 yieldk a r = liftIO (IO.hPutStrLn h a) >> go r
1405 yieldk a r = liftIO (IO.hPutStrLn h a) >> go r
1405 in K.foldStream defState yieldk single stop m1
1406 in K.foldStream defState yieldk single stop m1
1408+-- XXX rename these to write/writeRev to make the naming consistent with folds
1409+-- in other modules.
1407-- | A fold that buffers its input to a pure stream.
1411-- | A fold that buffers its input to a pure stream.
1409-- /Warning!/ working on large streams accumulated as buffers in memory could
1413-- /Warning!/ working on large streams accumulated as buffers in memory could
1410-- be very inefficient, consider using "Streamly.Array" instead.
1414-- be very inefficient, consider using "Streamly.Array" instead.
1412−-- @since 0.7.0
1416+-- /Internal/
1413{-# INLINE toStream #-}
1417{-# INLINE toStream #-}
1414toStream :: Monad m => Fold m a (SerialT Identity a)
1418toStream :: Monad m => Fold m a (SerialT Identity a)
1415toStream = Fold (\f x -> return $ f . (x `K.cons`))
1419toStream = Fold (\f x -> return $ f . (x `K.cons`))
@@ -1425,13 +1429,37 @@ toStream = Fold (\f x -> return $ f . (x `K.cons`))
1425-- /Warning!/ working on large streams accumulated as buffers in memory could
1429-- /Warning!/ working on large streams accumulated as buffers in memory could
1426-- be very inefficient, consider using "Streamly.Array" instead.
1430-- be very inefficient, consider using "Streamly.Array" instead.
1428−-- @since 0.7.0
1432+-- /Internal/
1430-- xn : ... : x2 : x1 : []
1434-- xn : ... : x2 : x1 : []
1431{-# INLINABLE toStreamRev #-}
1435{-# INLINABLE toStreamRev #-}
1432toStreamRev :: Monad m => Fold m a (SerialT Identity a)
1436toStreamRev :: Monad m => Fold m a (SerialT Identity a)
1433toStreamRev = Fold (\xs x -> return $ x `K.cons` xs) (return K.nil) return
1437toStreamRev = Fold (\xs x -> return $ x `K.cons` xs) (return K.nil) return
1439+-- | Convert a stream to a pure stream.
1442+-- toPure = foldr cons nil
1447+{-# INLINE toPure #-}
1448+toPure :: Monad m => SerialT m a -> m (SerialT Identity a)
1449+toPure = foldr K.cons K.nil
1451+-- | Convert a stream to a pure stream in reverse order.
1454+-- toPureRev = foldl' (flip cons) nil
1459+{-# INLINE toPureRev #-}
1460+toPureRev :: Monad m => SerialT m a -> m (SerialT Identity a)
1461+toPureRev = foldl' (flip K.cons) K.nil
1435------------------------------------------------------------------------------
1463------------------------------------------------------------------------------
1436-- General Transformation
1464-- General Transformation
1437------------------------------------------------------------------------------
1465------------------------------------------------------------------------------