@@ -94,12 +94,11 @@ import Prelude hiding (read)
94import qualified Control.Monad.Catch as MC
94import qualified Control.Monad.Catch as MC
95import qualified System.IO as SIO
95import qualified System.IO as SIO
97−import Streamly.Data.Fold (chunksOf)
97+import Streamly.Data.Fold (chunksOf, drain)
98import Streamly.Internal.Control.Concurrent (MonadAsync)
98import Streamly.Internal.Control.Concurrent (MonadAsync)
99import Streamly.Internal.Data.Array.Unboxed.Type (Array(..), writeNUnsafe)
99import Streamly.Internal.Data.Array.Unboxed.Type (Array(..), writeNUnsafe)
100import Streamly.Internal.Data.Fold.Type (Fold(..))
100import Streamly.Internal.Data.Fold.Type (Fold(..))
101−import Streamly.Internal.Data.Stream.Type (Stream)
101+import Streamly.Data.Stream (Stream)
102−import Streamly.Internal.Data.Stream.IsStream.Type (IsStream)
103import Streamly.Internal.Data.Unfold.Type (Unfold(..))
102import Streamly.Internal.Data.Unfold.Type (Unfold(..))
104-- import Streamly.String (encodeUtf8, decodeUtf8, foldLines)
103-- import Streamly.String (encodeUtf8, decodeUtf8, foldLines)
105import Streamly.Internal.System.IO (defaultChunkSize)
104import Streamly.Internal.System.IO (defaultChunkSize)
@@ -111,7 +110,7 @@ import qualified Streamly.Internal.Data.Fold.Type as FL
111import qualified Streamly.Internal.Data.Unfold as UF (bracket)
110import qualified Streamly.Internal.Data.Unfold as UF (bracket)
112import qualified Streamly.Internal.FileSystem.Handle as FH
111import qualified Streamly.Internal.FileSystem.Handle as FH
113import qualified Streamly.Internal.Data.Array.Stream.Foreign as AS
112import qualified Streamly.Internal.Data.Array.Stream.Foreign as AS
114−import qualified Streamly.Internal.Data.Stream.IsStream as S
113+import qualified Streamly.Data.Stream as S (fold, bracket, mapM)
116-------------------------------------------------------------------------------
115-------------------------------------------------------------------------------
117-- References
116-- References
@@ -140,8 +139,8 @@ import qualified Streamly.Internal.Data.Stream.IsStream as S
140-- /Pre-release/
139-- /Pre-release/
142{-# INLINE withFile #-}
141{-# INLINE withFile #-}
143−withFile :: (IsStream t, MonadCatch m, MonadAsync m)
142+withFile :: (MonadCatch m, MonadAsync m)
144− => FilePath -> IOMode -> (Handle -> t m a) -> t m a
143+ => FilePath -> IOMode -> (Handle -> Stream m a) -> Stream m a
145withFile file mode = S.bracket (liftIO $ openFile file mode) (liftIO . hClose)
144withFile file mode = S.bracket (liftIO $ openFile file mode) (liftIO . hClose)
147-- | Transform an 'Unfold' from a 'Handle' to an unfold from a 'FilePath'. The
146-- | Transform an 'Unfold' from a 'Handle' to an unfold from a 'FilePath'. The
@@ -219,8 +218,8 @@ appendArray file arr = SIO.withFile file AppendMode (`FH.putChunk` arr)
220-- @since 0.9.0
219-- @since 0.9.0
221{-# INLINE toChunksWith #-}
220{-# INLINE toChunksWith #-}
222−toChunksWith :: (IsStream t, MonadCatch m, MonadAsync m)
221+toChunksWith :: (MonadCatch m, MonadAsync m)
223− => Int -> FilePath -> t m (Array Word8)
222+ => Int -> FilePath -> Stream m (Array Word8)
224toChunksWith size file =
223toChunksWith size file =
225 withFile file ReadMode (FH.getChunksWith size)
224 withFile file ReadMode (FH.getChunksWith size)
@@ -234,8 +233,8 @@ toChunksWith size file =
235-- @since 0.7.0
234-- @since 0.7.0
236{-# INLINE toChunks #-}
235{-# INLINE toChunks #-}
237−toChunks :: (IsStream t, MonadCatch m, MonadAsync m)
236+toChunks :: (MonadCatch m, MonadAsync m)
238− => FilePath -> t m (Array Word8)
237+ => FilePath -> Stream m (Array Word8)
239toChunks = toChunksWith defaultChunkSize
238toChunks = toChunksWith defaultChunkSize
241-------------------------------------------------------------------------------
240-------------------------------------------------------------------------------
@@ -306,7 +305,7 @@ read = UF.many A.read (usingFile FH.readChunks)
306-- /Pre-release/
305-- /Pre-release/
308{-# INLINE toBytes #-}
307{-# INLINE toBytes #-}
309−toBytes :: (IsStream t, MonadCatch m, MonadAsync m) => FilePath -> t m Word8
308+toBytes :: (MonadCatch m, MonadAsync m) => FilePath -> Stream m Word8
310toBytes file = AS.concat $ withFile file ReadMode FH.getChunks
309toBytes file = AS.concat $ withFile file ReadMode FH.getChunks
@@ -316,7 +315,7 @@ toBytes file = AS.concat $ withFile file ReadMode FH.getChunks
317-- @since 0.7.0
316-- @since 0.7.0
318{-# INLINE readShared #-}
317{-# INLINE readShared #-}
319−readShared :: (IsStream t, MonadIO m) => Handle -> t m Word8
318+readShared :: MonadIO m => Handle -> Stream m Word8
320readShared = undefined
319readShared = undefined
@@ -327,7 +326,7 @@ readShared = undefined
327{-# INLINE fromChunksMode #-}
326{-# INLINE fromChunksMode #-}
328fromChunksMode :: (MonadAsync m, MonadCatch m)
327fromChunksMode :: (MonadAsync m, MonadCatch m)
329 => IOMode -> FilePath -> Stream m (Array a) -> m ()
328 => IOMode -> FilePath -> Stream m (Array a) -> m ()
330−fromChunksMode mode file xs = S.drain $
329+fromChunksMode mode file xs = S.fold drain $
331 withFile file mode (\h -> S.mapM (FH.putChunk h) xs)
330 withFile file mode (\h -> S.mapM (FH.putChunk h) xs)
333-- | Write a stream of arrays to a file. Overwrites the file if it exists.
332-- | Write a stream of arrays to a file. Overwrites the file if it exists.
@@ -470,7 +469,7 @@ appendShared = undefined
471-- @since 0.7.0
470-- @since 0.7.0
472{-# INLINE readUtf8 #-}
471{-# INLINE readUtf8 #-}
473−readUtf8 :: (IsStream t, MonadIO m) => Handle -> t m Char
472+readUtf8 :: MonadIO m => Handle -> Stream m Char
474readUtf8 = decodeUtf8 . read
473readUtf8 = decodeUtf8 . read
@@ -492,7 +491,7 @@ writeUtf8 h s = write h $ encodeUtf8 s
493-- @since 0.7.0
492-- @since 0.7.0
494{-# INLINE writeUtf8ByLines #-}
493{-# INLINE writeUtf8ByLines #-}
495−writeUtf8ByLines :: (IsStream t, MonadIO m) => Handle -> t m Char -> m ()
494+writeUtf8ByLines :: MonadIO m => Handle -> Stream m Char -> m ()
496writeUtf8ByLines = undefined
495writeUtf8ByLines = undefined
498-- | Read UTF-8 lines from a file handle and apply the specified fold to each
497-- | Read UTF-8 lines from a file handle and apply the specified fold to each
@@ -500,7 +499,7 @@ writeUtf8ByLines = undefined
501-- @since 0.7.0
500-- @since 0.7.0
502{-# INLINE readLines #-}
501{-# INLINE readLines #-}
503−readLines :: (IsStream t, MonadIO m) => Handle -> Fold m Char b -> t m b
502+readLines :: MonadIO m => Handle -> Fold m Char b -> Stream m b
504readLines h f = foldLines (readUtf8 h) f
503readLines h f = foldLines (readUtf8 h) f
506-------------------------------------------------------------------------------
505-------------------------------------------------------------------------------
@@ -513,8 +512,8 @@ readLines h f = foldLines (readUtf8 h) f
514-- @since 0.7.0
513-- @since 0.7.0
515{-# INLINE readFrames #-}
514{-# INLINE readFrames #-}
516−readFrames :: (IsStream t, MonadIO m, Storable a)
515+readFrames :: (MonadIO m, Storable a)
517− => Array a -> Handle -> Fold m a b -> t m b
516+ => Array a -> Handle -> Fold m a b -> Stream m b
518readFrames = undefined -- foldFrames . read
517readFrames = undefined -- foldFrames . read
520-- | Write a stream to the given file handle buffering up to frames separated
519-- | Write a stream to the given file handle buffering up to frames separated
@@ -522,8 +521,8 @@ readFrames = undefined -- foldFrames . read
523-- @since 0.7.0
522-- @since 0.7.0
524{-# INLINE writeByFrames #-}
523{-# INLINE writeByFrames #-}
525−writeByFrames :: (IsStream t, MonadIO m, Storable a)
524+writeByFrames :: (MonadIO m, Storable a)
526− => Array a -> Handle -> t m a -> m ()
525+ => Array a -> Handle -> Stream m a -> m ()
527writeByFrames = undefined
526writeByFrames = undefined
529-------------------------------------------------------------------------------
528-------------------------------------------------------------------------------
@@ -560,8 +559,8 @@ readIndex arr i = undefined
560-- chunk is aligned with @chunkSize@ from second chunk onwards.
559-- chunk is aligned with @chunkSize@ from second chunk onwards.
562{-# INLINE readSliceWith #-}
561{-# INLINE readSliceWith #-}
563−readSliceWith :: (IsStream t, MonadIO m, Storable a)
562+readSliceWith :: (MonadIO m, Storable a)
564− => Int -> Handle -> Int -> Int -> t m a
563+ => Int -> Handle -> Int -> Int -> Stream m a
565readSliceWith chunkSize h pos len = undefined
564readSliceWith chunkSize h pos len = undefined
567-- | @readSlice h i count@ streams a slice from the file handle @h@ starting
566-- | @readSlice h i count@ streams a slice from the file handle @h@ starting
@@ -570,8 +569,8 @@ readSliceWith chunkSize h pos len = undefined
571-- @since 0.7.0
570-- @since 0.7.0
572{-# INLINE readSlice #-}
571{-# INLINE readSlice #-}
573−readSlice :: (IsStream t, MonadIO m, Storable a)
572+readSlice :: (MonadIO m, Storable a)
574− => Handle -> Int -> Int -> t m a
573+ => Handle -> Int -> Int -> Stream m a
575readSlice = readSliceWith defaultChunkSize
574readSlice = readSliceWith defaultChunkSize
577-- | @readSliceRev h i count@ streams a slice from the file handle @h@ starting
576-- | @readSliceRev h i count@ streams a slice from the file handle @h@ starting
@@ -580,8 +579,8 @@ readSlice = readSliceWith defaultChunkSize
581-- @since 0.7.0
580-- @since 0.7.0
582{-# INLINE readSliceRev #-}
581{-# INLINE readSliceRev #-}
583−readSliceRev :: (IsStream t, MonadIO m, Storable a)
582+readSliceRev :: (MonadIO m, Storable a)
584− => Handle -> Int -> Int -> t m a
583+ => Handle -> Int -> Int -> Stream m a
585readSliceRev h i count = undefined
584readSliceRev h i count = undefined
587-- | Write the given element at the given index in the file.
586-- | Write the given element at the given index in the file.
@@ -597,8 +596,8 @@ writeIndex h i a = undefined
598-- @since 0.7.0
597-- @since 0.7.0
599{-# INLINE writeSlice #-}
598{-# INLINE writeSlice #-}
600−writeSlice :: (IsStream t, Monad m, Storable a)
599+writeSlice :: (Monad m, Storable a)
601− => Handle -> Int -> Int -> t m a -> m ()
600+ => Handle -> Int -> Int -> Stream m a -> m ()
602writeSlice h i len s = undefined
601writeSlice h i len s = undefined
604-- | @writeSliceRev h i count stream@ writes a stream to the file handle @h@
603-- | @writeSliceRev h i count stream@ writes a stream to the file handle @h@
@@ -607,7 +606,7 @@ writeSlice h i len s = undefined
608-- @since 0.7.0
607-- @since 0.7.0
609{-# INLINE writeSliceRev #-}
608{-# INLINE writeSliceRev #-}
610−writeSliceRev :: (IsStream t, Monad m, Storable a)
609+writeSliceRev :: (Monad m, Storable a)
611− => Handle -> Int -> Int -> t m a -> m ()
610+ => Handle -> Int -> Int -> Stream m a -> m ()
612writeSliceRev arr i len s = undefined
611writeSliceRev arr i len s = undefined