on master help sign in
Change the unfold/toStream naming for arrays (#2004)
e856425Harendra Kumar
benchmark/Streamly/Benchmark/Data/Array/Common.hs+4−4
@@ -69,7 +69,7 @@ onArray
69 :: MonadIO m => Int -> (Stream.Stream m Int -> Stream.Stream m Int)
69 :: MonadIO m => Int -> (Stream.Stream m Int -> Stream.Stream m Int)
70 -> Stream Int
70 -> Stream Int
71 -> m (Stream Int)
71 -> m (Stream Int)
72−onArray value f arr = S.fold (A.writeN value) $ f $ S.unfold A.read arr
72+onArray value f arr = S.fold (A.writeN value) $ f $ S.unfold A.reader arr
73
73
74scanl' value n = composeN n $ onArray value $ S.scanl' (+) 0
74scanl' value n = composeN n $ onArray value $ S.scanl' (+) 0
75scanl1' value n = composeN n $ onArray value $ S.scanl1' (+)
75scanl1' value n = composeN n $ onArray value $ S.scanl1' (+)
@@ -98,7 +98,7 @@ showInstance = P.show
98
98
99{-# INLINE pureFoldl' #-}
99{-# INLINE pureFoldl' #-}
100pureFoldl' :: MonadIO m => Stream Int -> m Int
100pureFoldl' :: MonadIO m => Stream Int -> m Int
101−pureFoldl' = S.foldl' (+) 0 . S.unfold A.read
101+pureFoldl' = S.foldl' (+) 0 . S.unfold A.reader
102
102
103-------------------------------------------------------------------------------
103-------------------------------------------------------------------------------
104-- Elimination
104-- Elimination
@@ -106,11 +106,11 @@ pureFoldl' = S.foldl' (+) 0 . S.unfold A.read
106
106
107{-# INLINE unfoldReadDrain #-}
107{-# INLINE unfoldReadDrain #-}
108unfoldReadDrain :: MonadIO m => Stream Int -> m ()
108unfoldReadDrain :: MonadIO m => Stream Int -> m ()
109−unfoldReadDrain = S.drain . S.unfold A.read
109+unfoldReadDrain = S.drain . S.unfold A.reader
110
110
111{-# INLINE toStreamRevDrain #-}
111{-# INLINE toStreamRevDrain #-}
112toStreamRevDrain :: MonadIO m => Stream Int -> m ()
112toStreamRevDrain :: MonadIO m => Stream Int -> m ()
113−toStreamRevDrain = S.drain . A.toStreamRev
113+toStreamRevDrain = S.drain . A.readRev
114
114
115-------------------------------------------------------------------------------
115-------------------------------------------------------------------------------
116-- Bench groups
116-- Bench groups
benchmark/Streamly/Benchmark/Data/Array/Stream/Unboxed.hs+1−1
@@ -108,7 +108,7 @@ inspect $ 'toChunksSumLengths `hasNoType` ''Step
108-- | Sum the bytes in a file.
108-- | Sum the bytes in a file.
109toChunksCountBytes :: Handle -> IO Word8
109toChunksCountBytes :: Handle -> IO Word8
110toChunksCountBytes inh = do
110toChunksCountBytes inh = do
111− let foldlArr' f z = runIdentity . Stream.foldl' f z . Array.toStream
111+ let foldlArr' f z = runIdentity . Stream.foldl' f z . Array.read
112 let s = Handle.readChunks inh
112 let s = Handle.readChunks inh
113 Stream.foldl' (\acc arr -> acc + foldlArr' (+) 0 arr) 0 s
113 Stream.foldl' (\acc arr -> acc + foldlArr' (+) 0 arr) 0 s
114
114
benchmark/Streamly/Benchmark/Data/Array/Unboxed.hs+1−1
@@ -7,7 +7,7 @@ import Control.DeepSeq (deepseq)
7import qualified Streamly.Internal.Data.Array.Unboxed as IA
7import qualified Streamly.Internal.Data.Array.Unboxed as IA
8import qualified GHC.Exts as GHC
8import qualified GHC.Exts as GHC
9
9
10−import qualified Streamly.Data.Array.Unboxed as A
10+-- import qualified Streamly.Data.Array.Unboxed as A
11import qualified Streamly.Internal.Data.Array.Unboxed as A
11import qualified Streamly.Internal.Data.Array.Unboxed as A
12type Stream = A.Array
12type Stream = A.Array
13
13
benchmark/Streamly/Benchmark/Data/Array/Unboxed/Mut.hs+5−5
@@ -158,7 +158,7 @@ onArray
158 -> Stream Int
158 -> Stream Int
159 -> m (Stream Int)
159 -> m (Stream Int)
160onArray value f arr =
160onArray value f arr =
161− Stream.fold (MArray.writeN value) $ f $ Stream.unfold MArray.read arr
161+ Stream.fold (MArray.writeN value) $ f $ Stream.unfold MArray.reader arr
162
162
163-------------------------------------------------------------------------------
163-------------------------------------------------------------------------------
164-- Elimination
164-- Elimination
@@ -166,11 +166,11 @@ onArray value f arr =
166
166
167{-# INLINE unfoldReadDrain #-}
167{-# INLINE unfoldReadDrain #-}
168unfoldReadDrain :: MonadIO m => Stream Int -> m ()
168unfoldReadDrain :: MonadIO m => Stream Int -> m ()
169−unfoldReadDrain = drain . Stream.unfold MArray.read
169+unfoldReadDrain = drain . Stream.unfold MArray.reader
170
170
171{-# INLINE unfoldReadRevDrain #-}
171{-# INLINE unfoldReadRevDrain #-}
172unfoldReadRevDrain :: MonadIO m => Stream Int -> m ()
172unfoldReadRevDrain :: MonadIO m => Stream Int -> m ()
173−unfoldReadRevDrain = drain . Stream.unfold MArray.readRev
173+unfoldReadRevDrain = drain . Stream.unfold MArray.readerRev
174
174
175{-# INLINE toStreamDRevDrain #-}
175{-# INLINE toStreamDRevDrain #-}
176toStreamDRevDrain :: MonadIO m => Stream Int -> m ()
176toStreamDRevDrain :: MonadIO m => Stream Int -> m ()
@@ -183,7 +183,7 @@ toStreamDDrain = drain . Stream.fromStreamD . MArray.toStreamD
183
183
184{-# INLINE unfoldFold #-}
184{-# INLINE unfoldFold #-}
185unfoldFold :: MonadIO m => Stream Int -> m Int
185unfoldFold :: MonadIO m => Stream Int -> m Int
186−unfoldFold = Stream.fold (Fold.foldl' (+) 0) . Stream.unfold MArray.read
186+unfoldFold = Stream.fold (Fold.foldl' (+) 0) . Stream.unfold MArray.reader
187
187
188-------------------------------------------------------------------------------
188-------------------------------------------------------------------------------
189-- Bench groups
189-- Bench groups
@@ -260,7 +260,7 @@ o_1_space_serial_marray value ~(array, indices) =
260 $ MArray.strip (> 0)
260 $ MArray.strip (> 0)
261 , benchIO' "modifyIndices (+ 1)" (const (return indices))
261 , benchIO' "modifyIndices (+ 1)" (const (return indices))
262 $ Stream.fold (MArray.modifyIndices (\_idx val -> val + 1) array)
262 $ Stream.fold (MArray.modifyIndices (\_idx val -> val + 1) array)
263− . Stream.unfold Array.read
263+ . Stream.unfold Array.reader
264 ]
264 ]
265
265
266-------------------------------------------------------------------------------
266-------------------------------------------------------------------------------
benchmark/Streamly/Benchmark/FileSystem/Handle/Read.hs+1−1
@@ -189,7 +189,7 @@ getChunksConcatUnfoldCountLines inh =
189 $ IUS.lines FL.drain
189 $ IUS.lines FL.drain
190 $ SS.decodeLatin1
190 $ SS.decodeLatin1
191 -- XXX replace with toBytes
191 -- XXX replace with toBytes
192− $ S.unfoldMany A.read (IFH.readChunks inh)
192+ $ S.unfoldMany A.reader (IFH.readChunks inh)
193
193
194#ifdef INSPECTION
194#ifdef INSPECTION
195inspect $ hasNoTypeClasses 'getChunksConcatUnfoldCountLines
195inspect $ hasNoTypeClasses 'getChunksConcatUnfoldCountLines
benchmark/Streamly/Benchmark/FileSystem/Handle/ReadWrite.hs+2−2
@@ -134,7 +134,7 @@ _readChunks inh devNull = IUF.fold fld unf inh
134 where
134 where
135
135
136 fld = FH.write devNull
136 fld = FH.write devNull
137− unf = IUF.many A.read FH.chunkReader
137+ unf = IUF.many A.reader FH.chunkReader
138
138
139-- | Send the chunk content to /dev/null
139-- | Send the chunk content to /dev/null
140-- Implicitly benchmarked via 'readWithFromBytesNull'
140-- Implicitly benchmarked via 'readWithFromBytesNull'
@@ -144,7 +144,7 @@ _readChunksWith inh devNull = IUF.fold fld unf (defaultChunkSize, inh)
144 where
144 where
145
145
146 fld = FH.write devNull
146 fld = FH.write devNull
147− unf = IUF.many A.read FH.chunkReaderWith
147+ unf = IUF.many A.reader FH.chunkReaderWith
148
148
149o_1_space_copy_fromBytes :: BenchEnv -> [Benchmark]
149o_1_space_copy_fromBytes :: BenchEnv -> [Benchmark]
150o_1_space_copy_fromBytes env =
150o_1_space_copy_fromBytes env =
benchmark/Streamly/Benchmark/Unicode/Char.hs+4−4
@@ -65,10 +65,10 @@ arrInput file = second (fmap Array.fromList) (strInput file)
65
65
66benchFunctions :: [(String, Array Char -> IO ())]
66benchFunctions :: [(String, Array Char -> IO ())]
67benchFunctions =
67benchFunctions =
68− [ ("NFD", IsStream.drain . normalize NFD . Array.toStream)
68+ [ ("NFD", IsStream.drain . normalize NFD . Array.read)
69− , ("NFKD", IsStream.drain . normalize NFKD . Array.toStream)
69+ , ("NFKD", IsStream.drain . normalize NFKD . Array.read)
70− , ("NFC", IsStream.drain . normalize NFC . Array.toStream)
70+ , ("NFC", IsStream.drain . normalize NFC . Array.read)
71− , ("NFKC", IsStream.drain . normalize NFKC . Array.toStream)
71+ , ("NFKC", IsStream.drain . normalize NFKC . Array.read)
72 ]
72 ]
73
73
74main :: IO ()
74main :: IO ()
benchmark/Streamly/Benchmark/Unicode/Stream.hs+1−1
@@ -87,7 +87,7 @@ linesUnlinesCopy inh outh =
87linesUnlinesArrayWord8Copy :: Handle -> Handle -> IO ()
87linesUnlinesArrayWord8Copy :: Handle -> Handle -> IO ()
88linesUnlinesArrayWord8Copy inh outh =
88linesUnlinesArrayWord8Copy inh outh =
89 Stream.fold (Handle.write outh)
89 Stream.fold (Handle.write outh)
90− $ Stream.interposeSuffix 10 Array.read
90+ $ Stream.interposeSuffix 10 Array.reader
91 $ Stream.splitOnSuffix (== 10) Array.write
91 $ Stream.splitOnSuffix (== 10) Array.write
92 $ Stream.unfold Handle.reader inh
92 $ Stream.unfold Handle.reader inh
93
93
core/src/Streamly/Data/Array.hs+7−7
@@ -22,19 +22,19 @@ module Streamly.Data.Array
22 , A.writeN
22 , A.writeN
23 , A.write
23 , A.write
24
24
25− -- * Elimination
25+ -- * Streams
26−
27− , A.toStream
28− , A.toStreamRev
29 , A.read
26 , A.read
27+ , A.readRev
28+
29+ -- * Unfolds
30+ , A.reader
30
31
31 -- * Random Access
32 -- * Random Access
33+ , A.length
32
34
33 -- * Folding Arrays
35 -- * Folding Arrays
34− , A.streamFold
36+ -- , A.streamFold
35 , A.fold
37 , A.fold
36−
37− , A.length
38 )
38 )
39where
39where
40
40
core/src/Streamly/Data/Array/Unboxed.hs+33−11
@@ -1,5 +1,3 @@
1−#include "inline.hs"
2−
3-- |
1-- |
4-- Module : Streamly.Data.Array.Unboxed
2-- Module : Streamly.Data.Array.Unboxed
5-- Copyright : (c) 2019 Composewell Technologies
3-- Copyright : (c) 2019 Composewell Technologies
@@ -53,11 +51,11 @@
53
51
54module Streamly.Data.Array.Unboxed
52module Streamly.Data.Array.Unboxed
55 (
53 (
54+ -- * Types
56 Unbox (..)
55 Unbox (..)
57 , A.Array
56 , A.Array
58
57
59− -- * Arrays
60− -- ** Construction
58+ -- * Construction
61 -- | When performance matters, the fastest way to generate an array is
59 -- | When performance matters, the fastest way to generate an array is
62 -- 'writeN'. 'IsList' and 'IsString' instances can be
60 -- 'writeN'. 'IsList' and 'IsString' instances can be
63 -- used to conveniently construct arrays from literal values.
61 -- used to conveniently construct arrays from literal values.
@@ -74,27 +72,37 @@ module Streamly.Data.Array.Unboxed
74 , A.write -- full buffer
72 , A.write -- full buffer
75 , writeLastN -- drop old (ring buffer)
73 , writeLastN -- drop old (ring buffer)
76
74
77− -- ** Elimination
75+ -- * Conversion
78 -- 'GHC.Exts.toList' from "GHC.Exts" can be used to convert an array to a
76 -- 'GHC.Exts.toList' from "GHC.Exts" can be used to convert an array to a
79 -- list.
77 -- list.
80−
81 , A.toList
78 , A.toList
82− , A.read
83− , A.readRev
84
79
80+ -- * Unfolds
81+ , A.reader
82+ , A.readerRev
83+
85− -- ** Casting
84+ -- * Casting
86 , cast
85 , cast
87 , asBytes
86 , asBytes
88
87
89− -- ** Random Access
88+ -- * Random Access
90 , A.length
89 , A.length
91 -- , (!!)
90 -- , (!!)
92 , A.getIndex
91 , A.getIndex
92+
93+ -- * Deprecated
94+ , read
95+ , readRev
93 )
96 )
94where
97where
95
98
99+#include "inline.hs"
100+
101+import Streamly.Internal.Data.Unfold (Unfold)
96−import Streamly.Internal.Data.Array.Unboxed as A
102+import Streamly.Internal.Data.Array.Unboxed as A hiding (read, readRev)
103+
97import Streamly.Internal.Data.Unboxed (Unbox (..))
104import Streamly.Internal.Data.Unboxed (Unbox (..))
105+import Prelude hiding (read)
98
106
99-- $setup
107-- $setup
100-- >>> :m
108-- >>> :m
@@ -104,3 +112,17 @@ import Streamly.Internal.Data.Unboxed (Unbox (..))
104-- >>> import Streamly.Data.Array.Unboxed (Array)
112-- >>> import Streamly.Data.Array.Unboxed (Array)
105-- >>> import qualified Streamly.Internal.Data.Stream as Stream
113-- >>> import qualified Streamly.Internal.Data.Stream as Stream
106-- >>> import qualified Streamly.Data.Array.Unboxed as Array
114-- >>> import qualified Streamly.Data.Array.Unboxed as Array
115+
116+-- | Same as 'reader'
117+--
118+{-# DEPRECATED read "Please use 'reader' instead" #-}
119+{-# INLINE_NORMAL read #-}
120+read :: (Monad m, Unbox a) => Unfold m (Array a) a
121+read = reader
122+
123+-- | Same as 'readerRev'
124+--
125+{-# DEPRECATED readRev "Please use 'readerRev' instead" #-}
126+{-# INLINE_NORMAL readRev #-}
127+readRev :: (Monad m, Unbox a) => Unfold m (Array a) a
128+readRev = readerRev
core/src/Streamly/Data/Array/Unboxed/Mut.hs+13−11
@@ -13,11 +13,11 @@
13
13
14module Streamly.Data.Array.Unboxed.Mut
14module Streamly.Data.Array.Unboxed.Mut
15 (
15 (
16+ -- * Types
16 Unbox (..)
17 Unbox (..)
17 , Array
18 , Array
18
19
19− -- * Arrays
20− -- ** Construction
20+ -- * Construction
21
21
22 -- Uninitialized Arrays
22 -- Uninitialized Arrays
23 , new
23 , new
@@ -30,29 +30,31 @@ module Streamly.Data.Array.Unboxed.Mut
30 , write -- full buffer
30 , write -- full buffer
31 -- writeLastN
31 -- writeLastN
32
32
33− -- ** Appending elements
33+ -- * Appending elements
34 , snoc
34 , snoc
35
35
36− -- ** Appending streams
36+ -- * Appending streams
37 , appendN
37 , appendN
38 , append
38 , append
39
39
40− -- ** Inplace mutation
40+ -- * Inplace mutation
41 , putIndex
41 , putIndex
42
42
43− -- ** Random access
43+ -- * Random access
44 , getIndex
44 , getIndex
45
45
46− -- ** Elimination
46+ -- * Conversion
47 , toList
47 , toList
48− , read
49− , readRev
50
48
49+ -- * Unfolds
50+ , reader
51+ , readerRev
52+
51− -- ** Casting
53+ -- * Casting
52 , cast
54 , cast
53 , asBytes
55 , asBytes
54
56
55− -- ** Size
57+ -- * Size
56 , length
58 , length
57 )
59 )
58where
60where
core/src/Streamly/Internal/Data/Array.hs+24−24
@@ -30,13 +30,13 @@ module Streamly.Internal.Data.Array
30
30
31 -- * Elimination
31 -- * Elimination
32 , length
32 , length
33− , read
33+ , reader
34
34
35 , toList
35 , toList
36− , toStreamD
36+ , readStreamD
37− , toStreamDRev
37+ , readRevStreamD
38− , toStream
38+ , read
39− , toStreamRev
39+ , readRev
40
40
41 , foldl'
41 , foldl'
42 , foldr
42 , foldr
@@ -173,9 +173,9 @@ fromList xs = unsafePerformIO $ fromStreamD $ D.fromList xs
173length :: Array a -> Int
173length :: Array a -> Int
174length = arrLen
174length = arrLen
175
175
176−{-# INLINE_NORMAL read #-}
176+{-# INLINE_NORMAL reader #-}
177−read :: MonadIO m => Unfold m (Array a) a
177+reader :: MonadIO m => Unfold m (Array a) a
178−read = Unfold.lmap unsafeThaw MArray.read
178+reader = Unfold.lmap unsafeThaw MArray.reader
179
179
180-------------------------------------------------------------------------------
180-------------------------------------------------------------------------------
181-- Elimination - to streams
181-- Elimination - to streams
@@ -191,23 +191,23 @@ toList arr = loop 0
191 loop i | i == len = []
191 loop i | i == len = []
192 loop i = getIndexUnsafe arr i : loop (i + 1)
192 loop i = getIndexUnsafe arr i : loop (i + 1)
193
193
194−{-# INLINE_NORMAL toStreamD #-}
194+{-# INLINE_NORMAL readStreamD #-}
195−toStreamD :: MonadIO m => Array a -> D.Stream m a
195+readStreamD :: MonadIO m => Array a -> D.Stream m a
196−toStreamD = MArray.toStreamD . unsafeThaw
196+readStreamD = MArray.toStreamD . unsafeThaw
197
197
198−{-# INLINE_NORMAL toStreamDRev #-}
198+{-# INLINE_NORMAL readRevStreamD #-}
199−toStreamDRev :: Monad m => Array a -> D.Stream m a
199+readRevStreamD :: Monad m => Array a -> D.Stream m a
200−toStreamDRev arr@Array{..} =
200+readRevStreamD arr@Array{..} =
201 D.map (getIndexUnsafe arr)
201 D.map (getIndexUnsafe arr)
202 $ D.enumerateFromThenToIntegral (arrLen - 1) (arrLen - 2) 0
202 $ D.enumerateFromThenToIntegral (arrLen - 1) (arrLen - 2) 0
203
203
204−{-# INLINE_EARLY toStream #-}
204+{-# INLINE_EARLY read #-}
205−toStream :: MonadIO m => Array a -> Stream m a
205+read :: MonadIO m => Array a -> Stream m a
206−toStream = Stream.fromStreamD . toStreamD
206+read = Stream.fromStreamD . readStreamD
207
207
208−{-# INLINE_EARLY toStreamRev #-}
208+{-# INLINE_EARLY readRev #-}
209−toStreamRev :: Monad m => Array a -> Stream m a
209+readRev :: Monad m => Array a -> Stream m a
210−toStreamRev = Stream.fromStreamD . toStreamDRev
210+readRev = Stream.fromStreamD . readRevStreamD
211
211
212-------------------------------------------------------------------------------
212-------------------------------------------------------------------------------
213-- Elimination - using Folds
213-- Elimination - using Folds
@@ -215,11 +215,11 @@ toStreamRev = Stream.fromStreamD . toStreamDRev
215
215
216{-# INLINE_NORMAL foldl' #-}
216{-# INLINE_NORMAL foldl' #-}
217foldl' :: (b -> a -> b) -> b -> Array a -> b
217foldl' :: (b -> a -> b) -> b -> Array a -> b
218−foldl' f z arr = unsafePerformIO $ D.foldl' f z $ toStreamD arr
218+foldl' f z arr = unsafePerformIO $ D.foldl' f z $ readStreamD arr
219
219
220{-# INLINE_NORMAL foldr #-}
220{-# INLINE_NORMAL foldr #-}
221foldr :: (a -> b -> b) -> b -> Array a -> b
221foldr :: (a -> b -> b) -> b -> Array a -> b
222−foldr f z arr = unsafePerformIO $ D.foldr f z $ toStreamD arr
222+foldr f z arr = unsafePerformIO $ D.foldr f z $ readStreamD arr
223
223
224instance NFData a => NFData (Array a) where
224instance NFData a => NFData (Array a) where
225 {-# INLINE rnf #-}
225 {-# INLINE rnf #-}
@@ -227,11 +227,11 @@ instance NFData a => NFData (Array a) where
227
227
228{-# INLINE fold #-}
228{-# INLINE fold #-}
229fold :: MonadIO m => Fold m a b -> Array a -> m b
229fold :: MonadIO m => Fold m a b -> Array a -> m b
230−fold f arr = D.fold f (toStreamD arr)
230+fold f arr = D.fold f (readStreamD arr)
231
231
232{-# INLINE streamFold #-}
232{-# INLINE streamFold #-}
233streamFold :: MonadIO m => (Stream m a -> m b) -> Array a -> m b
233streamFold :: MonadIO m => (Stream m a -> m b) -> Array a -> m b
234−streamFold f arr = f (toStream arr)
234+streamFold f arr = f (read arr)
235
235
236-------------------------------------------------------------------------------
236-------------------------------------------------------------------------------
237-- Random reads and writes
237-- Random reads and writes
core/src/Streamly/Internal/Data/Array/Mut/Type.hs+7−9
@@ -84,9 +84,10 @@ module Streamly.Internal.Data.Array.Mut.Type
84
84
85 -- * Eliminating and Reading
85 -- * Eliminating and Reading
86
86
87− -- ** To streams
87+ -- ** Unfolds
88− , read
88+ , reader
89− -- , readRev
89+ -- , readerRev
90+ , producer -- experimental
90
91
91 -- ** To containers
92 -- ** To containers
92 , toStreamD
93 , toStreamD
@@ -95,9 +96,6 @@ module Streamly.Internal.Data.Array.Mut.Type
95 -- , toStreamKRev
96 -- , toStreamKRev
96 , toList
97 , toList
97
98
98− -- experimental
99− , producer
100−
101 -- ** Random reads
99 -- ** Random reads
102 , getIndex
100 , getIndex
103 , getIndexUnsafe
101 , getIndexUnsafe
@@ -570,9 +568,9 @@ producer = Producer step inject extract
570
568
571-- | Unfold an array into a stream.
569-- | Unfold an array into a stream.
572--
570--
573−{-# INLINE_NORMAL read #-}
571+{-# INLINE_NORMAL reader #-}
574−read :: MonadIO m => Unfold m (Array a) a
572+reader :: MonadIO m => Unfold m (Array a) a
575−read = Producer.simplify producer
573+reader = Producer.simplify producer
576
574
577--------------------------------------------------------------------------------
575--------------------------------------------------------------------------------
578-- Appending arrays
576-- Appending arrays
core/src/Streamly/Internal/Data/Array/Unboxed.hs+25−16
@@ -49,12 +49,17 @@ module Streamly.Internal.Data.Array.Unboxed
49 , writeLastN
49 , writeLastN
50
50
51 -- * Elimination
51 -- * Elimination
52+ -- ** Conversion
52 , A.toList
53 , A.toList
53− , A.toStream
54+
54− , A.toStreamRev
55+ -- ** Streams
55− , read
56+ , A.read
56− , unsafeRead -- XXX readUnsafe?
57 , A.readRev
57 , A.readRev
58+
59+ -- ** Unfolds
60+ , reader
61+ , readerUnsafe
62+ , A.readerRev
58 , producer -- experimental
63 , producer -- experimental
59
64
60 -- * Random Access
65 -- * Random Access
@@ -103,6 +108,10 @@ module Streamly.Internal.Data.Array.Unboxed
103 -- ** Folding
108 -- ** Folding
104 , streamFold
109 , streamFold
105 , fold
110 , fold
111+
112+ -- * Deprecated
113+ , A.toStream
114+ , A.toStreamRev
106 )
115 )
107where
116where
108
117
@@ -187,12 +196,10 @@ producer =
187
196
188-- | Unfold an array into a stream.
197-- | Unfold an array into a stream.
189--
198--
190−-- /Since 0.7.0 (Streamly.Memory.Array)/
191−--
192−-- @since 0.8.0
199+-- @since 0.9.0
193−{-# INLINE_NORMAL read #-}
200+{-# INLINE_NORMAL reader #-}
194−read :: forall m a. (Monad m, Unboxed a) => Unfold m (Array a) a
201+reader :: forall m a. (Monad m, Unboxed a) => Unfold m (Array a) a
195−read = Producer.simplify producer
202+reader = Producer.simplify producer
196
203
197-- | Unfold an array into a stream, does not check the end of the array, the
204-- | Unfold an array into a stream, does not check the end of the array, the
198-- user is responsible for terminating the stream within the array bounds. For
205-- user is responsible for terminating the stream within the array bounds. For
@@ -205,9 +212,9 @@ read = Producer.simplify producer
205--
212--
206-- /Pre-release/
213-- /Pre-release/
207--
214--
208−{-# INLINE_NORMAL unsafeRead #-}
215+{-# INLINE_NORMAL readerUnsafe #-}
209−unsafeRead :: forall m a. (Monad m, Unboxed a) => Unfold m (Array a) a
216+readerUnsafe :: forall m a. (Monad m, Unboxed a) => Unfold m (Array a) a
210−unsafeRead = Unfold step inject
217+readerUnsafe = Unfold step inject
211 where
218 where
212
219
213 inject (Array contents start end) =
220 inject (Array contents start end) =
@@ -484,7 +491,7 @@ runPipe f arr = P.runPipe (toArrayMinChunk (length arr)) $ f (A.read arr)
484streamTransform :: forall m a b. (MonadIO m, Unboxed a, Unboxed b)
491streamTransform :: forall m a b. (MonadIO m, Unboxed a, Unboxed b)
485 => (Stream m a -> Stream m b) -> Array a -> m (Array b)
492 => (Stream m a -> Stream m b) -> Array a -> m (Array b)
486streamTransform f arr =
493streamTransform f arr =
487− P.fold (A.writeWith (length arr)) $ Stream.toStreamK $ f (A.toStream arr)
494+ P.fold (A.writeWith (length arr)) $ Stream.toStreamK $ f (A.read arr)
488
495
489-------------------------------------------------------------------------------
496-------------------------------------------------------------------------------
490-- Casts
497-- Casts
@@ -544,16 +551,18 @@ asCStringUnsafe arr act = do
544-- Folds
551-- Folds
545-------------------------------------------------------------------------------
552-------------------------------------------------------------------------------
546
553
554+-- XXX We can directly use toStreamD and D.fold here.
555+
547-- | Fold an array using a 'Fold'.
556-- | Fold an array using a 'Fold'.
548--
557--
549-- /Pre-release/
558-- /Pre-release/
550{-# INLINE fold #-}
559{-# INLINE fold #-}
551fold :: forall m a b. (Monad m, Unboxed a) => Fold m a b -> Array a -> m b
560fold :: forall m a b. (Monad m, Unboxed a) => Fold m a b -> Array a -> m b
552−fold f arr = P.fold f (Stream.toStreamK (A.toStream arr))
561+fold f arr = P.fold f (Stream.toStreamK (A.read arr))
553
562
554-- | Fold an array using a stream fold operation.
563-- | Fold an array using a stream fold operation.
555--
564--
556-- /Pre-release/
565-- /Pre-release/
557{-# INLINE streamFold #-}
566{-# INLINE streamFold #-}
558streamFold :: (Monad m, Unboxed a) => (Stream m a -> m b) -> Array a -> m b
567streamFold :: (Monad m, Unboxed a) => (Stream m a -> m b) -> Array a -> m b
559−streamFold f arr = f (A.toStream arr)
568+streamFold f arr = f (A.read arr)
core/src/Streamly/Internal/Data/Array/Unboxed/Mut/Type.hs+22−22
@@ -96,9 +96,9 @@ module Streamly.Internal.Data.Array.Unboxed.Mut.Type
96 -- * Eliminating and Reading
96 -- * Eliminating and Reading
97
97
98 -- ** To streams
98 -- ** To streams
99− , read
99+ , reader
100− , readRevWith
100+ , readerRevWith
101− , readRev
101+ , readerRev
102
102
103 -- ** To containers
103 -- ** To containers
104 , toStreamDWith
104 , toStreamDWith
@@ -1088,7 +1088,7 @@ getSlice index len (Array contents start e _) =
1088-- XXX consider the bulk update/accumulation/permutation APIs from vector.
1088-- XXX consider the bulk update/accumulation/permutation APIs from vector.
1089
1089
1090-- | You may not need to reverse an array because you can consume it in reverse
1090-- | You may not need to reverse an array because you can consume it in reverse
1091−-- using 'readRev'. To reverse large arrays you can read in reverse and write
1091+-- using 'readerRev'. To reverse large arrays you can read in reverse and write
1092-- to another array. However, in-place reverse can be useful to take adavantage
1092-- to another array. However, in-place reverse can be useful to take adavantage
1093-- of cache locality and when you do not want to allocate additional memory.
1093-- of cache locality and when you do not want to allocate additional memory.
1094--
1094--
@@ -1350,9 +1350,9 @@ data FlattenState s contents a =
1350 OuterLoop s
1350 OuterLoop s
1351 | InnerLoop s contents !Int !Int
1351 | InnerLoop s contents !Int !Int
1352
1352
1353−-- | Use the "read" unfold instead.
1353+-- | Use the "reader" unfold instead.
1354--
1354--
1355−-- @flattenArrays = unfoldMany read@
1355+-- @flattenArrays = unfoldMany reader@
1356--
1356--
1357-- We can try this if there are any fusion issues in the unfold.
1357-- We can try this if there are any fusion issues in the unfold.
1358--
1358--
@@ -1379,9 +1379,9 @@ flattenArrays (D.Stream step state) = D.Stream step' (OuterLoop state)
1379 x <- liftIO $ peekWith contents p
1379 x <- liftIO $ peekWith contents p
1380 return $ D.Yield x (InnerLoop st contents (INDEX_NEXT(p,a)) end)
1380 return $ D.Yield x (InnerLoop st contents (INDEX_NEXT(p,a)) end)
1381
1381
1382−-- | Use the "readRev" unfold instead.
1382+-- | Use the "readerRev" unfold instead.
1383--
1383--
1384−-- @flattenArrays = unfoldMany readRev@
1384+-- @flattenArrays = unfoldMany readerRev@
1385--
1385--
1386-- We can try this if there are any fusion issues in the unfold.
1386-- We can try this if there are any fusion issues in the unfold.
1387--
1387--
@@ -1459,15 +1459,15 @@ producer = producerWith liftIO
1459-- | Unfold an array into a stream.
1459-- | Unfold an array into a stream.
1460--
1460--
1461-- @since 0.7.0
1461-- @since 0.7.0
1462−{-# INLINE_NORMAL read #-}
1462+{-# INLINE_NORMAL reader #-}
1463−read :: forall m a. (MonadIO m, Unboxed a) => Unfold m (Array a) a
1463+reader :: forall m a. (MonadIO m, Unboxed a) => Unfold m (Array a) a
1464−read = Producer.simplify producer
1464+reader = Producer.simplify producer
1465
1465
1466−{-# INLINE_NORMAL readRevWith #-}
1466+{-# INLINE_NORMAL readerRevWith #-}
1467−readRevWith ::
1467+readerRevWith ::
1468 forall m a. (Monad m, Unboxed a)
1468 forall m a. (Monad m, Unboxed a)
1469 => (forall b. IO b -> m b) -> Unfold m (Array a) a
1469 => (forall b. IO b -> m b) -> Unfold m (Array a) a
1470−readRevWith liftio = Unfold step inject
1470+readerRevWith liftio = Unfold step inject
1471 where
1471 where
1472
1472
1473 inject (Array contents start end _) =
1473 inject (Array contents start end _) =
@@ -1483,9 +1483,9 @@ readRevWith liftio = Unfold step inject
1483-- | Unfold an array into a stream in reverse order.
1483-- | Unfold an array into a stream in reverse order.
1484--
1484--
1485-- /Pre-release/
1485-- /Pre-release/
1486−{-# INLINE_NORMAL readRev #-}
1486+{-# INLINE_NORMAL readerRev #-}
1487−readRev :: forall m a. (MonadIO m, Unboxed a) => Unfold m (Array a) a
1487+readerRev :: forall m a. (MonadIO m, Unboxed a) => Unfold m (Array a) a
1488−readRev = readRevWith liftIO
1488+readerRev = readerRevWith liftIO
1489
1489
1490-------------------------------------------------------------------------------
1490-------------------------------------------------------------------------------
1491-- to Lists and streams
1491-- to Lists and streams
@@ -1543,9 +1543,9 @@ toStreamDWith liftio Array{..} = D.Stream step arrStart
1543 r <- peekWith arrContents p
1543 r <- peekWith arrContents p
1544 return $ D.Yield r (INDEX_NEXT(p,a))
1544 return $ D.Yield r (INDEX_NEXT(p,a))
1545
1545
1546−-- | Use the 'read' unfold instead.
1546+-- | Use the 'reader' unfold instead.
1547--
1547--
1548−-- @toStreamD = D.unfold read@
1548+-- @toStreamD = D.unfold reader@
1549--
1549--
1550-- We can try this if the unfold has any performance issues.
1550-- We can try this if the unfold has any performance issues.
1551{-# INLINE_NORMAL toStreamD #-}
1551{-# INLINE_NORMAL toStreamD #-}
@@ -1585,9 +1585,9 @@ toStreamDRevWith liftio Array{..} =
1585 r <- peekWith arrContents p
1585 r <- peekWith arrContents p
1586 return $ D.Yield r (INDEX_PREV(p,a))
1586 return $ D.Yield r (INDEX_PREV(p,a))
1587
1587
1588−-- | Use the 'readRev' unfold instead.
1588+-- | Use the 'readerRev' unfold instead.
1589--
1589--
1590−-- @toStreamDRev = D.unfold readRev@
1590+-- @toStreamDRev = D.unfold readerRev@
1591--
1591--
1592-- We can try this if the unfold has any perf issues.
1592-- We can try this if the unfold has any perf issues.
1593{-# INLINE_NORMAL toStreamDRev #-}
1593{-# INLINE_NORMAL toStreamDRev #-}
@@ -1970,7 +1970,7 @@ fromArrayStreamK :: (Unboxed a, MonadIO m) =>
1970 K.Stream m (Array a) -> m (Array a)
1970 K.Stream m (Array a) -> m (Array a)
1971fromArrayStreamK as = do
1971fromArrayStreamK as = do
1972 len <- arrayStreamKLength as
1972 len <- arrayStreamKLength as
1973− fromStreamDN len $ D.unfoldMany read $ D.fromStreamK as
1973+ fromStreamDN len $ D.unfoldMany reader $ D.fromStreamK as
1974
1974
1975-- CAUTION: a very large number (millions) of arrays can degrade performance
1975-- CAUTION: a very large number (millions) of arrays can degrade performance
1976-- due to GC overhead because we need to buffer the arrays before we flatten
1976-- due to GC overhead because we need to buffer the arrays before we flatten
core/src/Streamly/Internal/Data/Array/Unboxed/Stream.hs+6−6
@@ -130,18 +130,18 @@ arraysOf n str = fromStreamD $ A.arraysOf n (toStreamD str)
130concat :: (Monad m, Unboxed a) => Stream m (Array a) -> Stream m a
130concat :: (Monad m, Unboxed a) => Stream m (Array a) -> Stream m a
131-- concat m = fromStreamD $ A.flattenArrays (toStreamD m)
131-- concat m = fromStreamD $ A.flattenArrays (toStreamD m)
132-- concat m = fromStreamD $ D.concatMap A.toStreamD (toStreamD m)
132-- concat m = fromStreamD $ D.concatMap A.toStreamD (toStreamD m)
133−concat m = fromStreamD $ D.unfoldMany A.read (toStreamD m)
133+concat m = fromStreamD $ D.unfoldMany A.reader (toStreamD m)
134
134
135-- | Convert a stream of arrays into a stream of their elements reversing the
135-- | Convert a stream of arrays into a stream of their elements reversing the
136-- contents of each array before flattening.
136-- contents of each array before flattening.
137--
137--
138−-- > concatRev = Stream.unfoldMany Array.readRev
138+-- > concatRev = Stream.unfoldMany Array.readerRev
139--
139--
140-- @since 0.7.0
140-- @since 0.7.0
141{-# INLINE concatRev #-}
141{-# INLINE concatRev #-}
142concatRev :: (Monad m, Unboxed a) => Stream m (Array a) -> Stream m a
142concatRev :: (Monad m, Unboxed a) => Stream m (Array a) -> Stream m a
143-- concatRev m = fromStreamD $ A.flattenArraysRev (toStreamD m)
143-- concatRev m = fromStreamD $ A.flattenArraysRev (toStreamD m)
144−concatRev m = fromStreamD $ D.unfoldMany A.readRev (toStreamD m)
144+concatRev m = fromStreamD $ D.unfoldMany A.readerRev (toStreamD m)
145
145
146-------------------------------------------------------------------------------
146-------------------------------------------------------------------------------
147-- Intersperse and append
147-- Intersperse and append
@@ -153,12 +153,12 @@ concatRev m = fromStreamD $ D.unfoldMany A.readRev (toStreamD m)
153-- /Pre-release/
153-- /Pre-release/
154{-# INLINE interpose #-}
154{-# INLINE interpose #-}
155interpose :: (Monad m, Unboxed a) => a -> Stream m (Array a) -> Stream m a
155interpose :: (Monad m, Unboxed a) => a -> Stream m (Array a) -> Stream m a
156−interpose x = S.interpose x A.read
156+interpose x = S.interpose x A.reader
157
157
158{-# INLINE intercalateSuffix #-}
158{-# INLINE intercalateSuffix #-}
159intercalateSuffix :: (Monad m, Unboxed a)
159intercalateSuffix :: (Monad m, Unboxed a)
160 => Array a -> Stream m (Array a) -> Stream m a
160 => Array a -> Stream m (Array a) -> Stream m a
161−intercalateSuffix = S.intercalateSuffix A.read
161+intercalateSuffix = S.intercalateSuffix A.reader
162
162
163-- | Flatten a stream of arrays appending the given element after each
163-- | Flatten a stream of arrays appending the given element after each
164-- array.
164-- array.
@@ -168,7 +168,7 @@ intercalateSuffix = S.intercalateSuffix A.read
168interposeSuffix :: (Monad m, Unboxed a)
168interposeSuffix :: (Monad m, Unboxed a)
169 => a -> Stream m (Array a) -> Stream m a
169 => a -> Stream m (Array a) -> Stream m a
170-- interposeSuffix x = fromStreamD . A.unlines x . toStreamD
170-- interposeSuffix x = fromStreamD . A.unlines x . toStreamD
171−interposeSuffix x = S.interposeSuffix x A.read
171+interposeSuffix x = S.interposeSuffix x A.reader
172
172
173data FlattenState s a =
173data FlattenState s a =
174 OuterLoop s
174 OuterLoop s
core/src/Streamly/Internal/Data/Array/Unboxed/Type.hs+24−8
@@ -39,7 +39,7 @@ module Streamly.Internal.Data.Array.Unboxed.Type
39
39
40 -- * Elimination
40 -- * Elimination
41 , unsafeIndexIO
41 , unsafeIndexIO
42− , unsafeIndex
42+ , unsafeIndex -- getIndexUnsafe
43 , byteLength
43 , byteLength
44 , length
44 , length
45
45
@@ -47,13 +47,15 @@ module Streamly.Internal.Data.Array.Unboxed.Type
47 , foldr
47 , foldr
48 , splitAt
48 , splitAt
49
49
50− , readRev
51 , toStreamD
50 , toStreamD
52 , toStreamDRev
51 , toStreamDRev
53 , toStreamK
52 , toStreamK
54 , toStreamKRev
53 , toStreamKRev
55 , toStream
54 , toStream
56 , toStreamRev
55 , toStreamRev
56+ , read
57+ , readRev
58+ , readerRev
57 , toList
59 , toList
58
60
59 -- * Folds
61 -- * Folds
@@ -341,10 +343,10 @@ length arr = MA.length (unsafeThaw arr)
341
343
342-- | Unfold an array into a stream in reverse order.
344-- | Unfold an array into a stream in reverse order.
343--
345--
344−-- @since 0.8.0
346+-- @since 0.9.0
345−{-# INLINE_NORMAL readRev #-}
347+{-# INLINE_NORMAL readerRev #-}
346−readRev :: forall m a. (Monad m, Unboxed a) => Unfold m (Array a) a
348+readerRev :: forall m a. (Monad m, Unboxed a) => Unfold m (Array a) a
347−readRev = Unfold.lmap unsafeThaw $ MA.readRevWith (return . unsafeInlineIO)
349+readerRev = Unfold.lmap unsafeThaw $ MA.readerRevWith (return . unsafeInlineIO)
348
350
349{-# INLINE_NORMAL toStreamD #-}
351{-# INLINE_NORMAL toStreamD #-}
350toStreamD :: forall m a. (Monad m, Unboxed a) => Array a -> D.Stream m a
352toStreamD :: forall m a. (Monad m, Unboxed a) => Array a -> D.Stream m a
@@ -367,9 +369,16 @@ toStreamKRev arr =
367-- | Convert an 'Array' into a stream.
369-- | Convert an 'Array' into a stream.
368--
370--
369-- /Pre-release/
371-- /Pre-release/
372+{-# INLINE_EARLY read #-}
373+read :: (Monad m, Unboxed a) => Array a -> Stream m a
374+read = Stream.fromStreamD . toStreamD
375+
376+-- | Same as 'read'
377+--
378+{-# DEPRECATED toStream "Please use 'read' instead." #-}
370{-# INLINE_EARLY toStream #-}
379{-# INLINE_EARLY toStream #-}
371toStream :: (Monad m, Unboxed a) => Array a -> Stream m a
380toStream :: (Monad m, Unboxed a) => Array a -> Stream m a
372−toStream = Stream.fromStreamD . toStreamD
381+toStream = read
373-- XXX add fallback to StreamK rule
382-- XXX add fallback to StreamK rule
374-- {-# RULES "Streamly.Array.read fallback to StreamK" [1]
383-- {-# RULES "Streamly.Array.read fallback to StreamK" [1]
375-- forall a. S.readK (read a) = K.fromArray a #-}
384-- forall a. S.readK (read a) = K.fromArray a #-}
@@ -377,9 +386,16 @@ toStream = Stream.fromStreamD . toStreamD
377-- | Convert an 'Array' into a stream in reverse order.
386-- | Convert an 'Array' into a stream in reverse order.
378--
387--
379-- /Pre-release/
388-- /Pre-release/
389+{-# INLINE_EARLY readRev #-}
390+readRev :: (Monad m, Unboxed a) => Array a -> Stream m a
391+readRev = Stream.fromStreamD . toStreamDRev
392+
393+-- | Same as 'readRev'
394+--
395+{-# DEPRECATED toStreamRev "Please use 'readRev' instead." #-}
380{-# INLINE_EARLY toStreamRev #-}
396{-# INLINE_EARLY toStreamRev #-}
381toStreamRev :: (Monad m, Unboxed a) => Array a -> Stream m a
397toStreamRev :: (Monad m, Unboxed a) => Array a -> Stream m a
382−toStreamRev = Stream.fromStreamD . toStreamDRev
398+toStreamRev = readRev
383
399
384-- XXX add fallback to StreamK rule
400-- XXX add fallback to StreamK rule
385-- {-# RULES "Streamly.Array.readRev fallback to StreamK" [1]
401-- {-# RULES "Streamly.Array.readRev fallback to StreamK" [1]
core/src/Streamly/Internal/Data/Stream/Top.hs+3−3
@@ -376,8 +376,8 @@ joinOuter eq s1 s =
376 where
376 where
377
377
378 leftOver inputArr foundArr =
378 leftOver inputArr foundArr =
379− let stream1 = Array.toStream inputArr
379+ let stream1 = Array.read inputArr
380− stream2 = Stream.unfold MA.read foundArr
380+ stream2 = Stream.unfold MA.reader foundArr
381 in Stream.filter
381 in Stream.filter
382 isJust
382 isJust
383 ( Stream.zipWith (\x y ->
383 ( Stream.zipWith (\x y ->
@@ -399,7 +399,7 @@ joinOuter eq s1 s =
399 then Stream.nil
399 then Stream.nil
400 else Stream.fromPure Nothing
400 else Stream.fromPure Nothing
401 (i, b) <-
401 (i, b) <-
402− let stream = Array.toStream inputArr
402+ let stream = Array.read inputArr
403 in Stream.indexed $ fmap Just (Stream.liftInner stream) <> final
403 in Stream.indexed $ fmap Just (Stream.liftInner stream) <> final
404
404
405 case b of
405 case b of
core/src/Streamly/Internal/FileSystem/Handle.hs+6−6
@@ -332,12 +332,12 @@ chunkReader = UF.first defaultChunkSize chunkReaderWith
332-- | Unfolds the tuple @(bufsize, handle)@ into a byte stream, read requests
332-- | Unfolds the tuple @(bufsize, handle)@ into a byte stream, read requests
333-- to the IO device are performed using buffers of @bufsize@.
333-- to the IO device are performed using buffers of @bufsize@.
334--
334--
335−-- >>> readerWith = Unfold.many Array.read Handle.chunkReaderWith
335+-- >>> readerWith = Unfold.many Array.reader Handle.chunkReaderWith
336--
336--
337-- @since 0.9.0
337-- @since 0.9.0
338{-# INLINE readerWith #-}
338{-# INLINE readerWith #-}
339readerWith :: MonadIO m => Unfold m (Int, Handle) Word8
339readerWith :: MonadIO m => Unfold m (Int, Handle) Word8
340−readerWith = UF.many A.read chunkReaderWith
340+readerWith = UF.many A.reader chunkReaderWith
341
341
342-- | Same as 'readerWith'
342-- | Same as 'readerWith'
343--
343--
@@ -350,7 +350,7 @@ readWithBufferOf = readerWith
350-- | @readWith bufsize handle@ reads a byte stream from a file
350-- | @readWith bufsize handle@ reads a byte stream from a file
351-- handle, reads are performed in chunks of up to @bufsize@.
351-- handle, reads are performed in chunks of up to @bufsize@.
352--
352--
353−-- >>> readWith size h = Stream.unfoldMany Array.read $ Handle.readChunksWith size h
353+-- >>> readWith size h = Stream.unfoldMany Array.reader $ Handle.readChunksWith size h
354--
354--
355-- /Pre-release/
355-- /Pre-release/
356{-# INLINE readWith #-}
356{-# INLINE readWith #-}
@@ -361,16 +361,16 @@ readWith size h = AS.concat $ readChunksWith size h
361-- performed in sizes of
361-- performed in sizes of
362-- 'Streamly.Internal.Data.Array.Unboxed.Type.defaultChunkSize'.
362-- 'Streamly.Internal.Data.Array.Unboxed.Type.defaultChunkSize'.
363--
363--
364−-- >>> reader = Unfold.many Array.read chunkReader
364+-- >>> reader = Unfold.many Array.reader chunkReader
365--
365--
366-- @since 0.9.0
366-- @since 0.9.0
367{-# INLINE reader #-}
367{-# INLINE reader #-}
368reader :: MonadIO m => Unfold m Handle Word8
368reader :: MonadIO m => Unfold m Handle Word8
369−reader = UF.many A.read chunkReader
369+reader = UF.many A.reader chunkReader
370
370
371-- | Generate a byte stream from a file 'Handle'.
371-- | Generate a byte stream from a file 'Handle'.
372--
372--
373−-- >>> read h = Stream.unfoldMany Array.read $ Handle.readChunks h
373+-- >>> read h = Stream.unfoldMany Array.reader $ Handle.readChunks h
374--
374--
375-- /Pre-release/
375-- /Pre-release/
376{-# INLINE read #-}
376{-# INLINE read #-}
core/src/Streamly/Internal/Unicode/Array/Char.hs+2−2
@@ -72,7 +72,7 @@ words = S.words A.write
72-- > unlines . lines /= id
72-- > unlines . lines /= id
73{-# INLINE unlines #-}
73{-# INLINE unlines #-}
74unlines :: MonadIO m => Stream m (Array Char) -> Stream m Char
74unlines :: MonadIO m => Stream m (Array Char) -> Stream m Char
75−unlines = S.unlines A.read
75+unlines = S.unlines A.reader
76
76
77-- | Flattens the stream of @Array Char@, after appending a separating
77-- | Flattens the stream of @Array Char@, after appending a separating
78-- space to each string.
78-- space to each string.
@@ -89,4 +89,4 @@ unlines = S.unlines A.read
89-- > unwords . words /= id
89-- > unwords . words /= id
90{-# INLINE unwords #-}
90{-# INLINE unwords #-}
91unwords :: MonadIO m => Stream m (Array Char) -> Stream m Char
91unwords :: MonadIO m => Stream m (Array Char) -> Stream m Char
92−unwords = S.unwords A.read
92+unwords = S.unwords A.reader
src/Streamly/Internal/Data/Stream/IsStream/Reduce.hs+2−2
@@ -182,7 +182,7 @@ import Streamly.Internal.Data.Unboxed (Unboxed)
182import qualified Data.Heap as H
182import qualified Data.Heap as H
183import qualified Streamly.Data.Unfold as Unfold
183import qualified Streamly.Data.Unfold as Unfold
184import qualified Streamly.Internal.Data.Array.Unboxed.Type as A
184import qualified Streamly.Internal.Data.Array.Unboxed.Type as A
185− (arraysOf, toStream)
185+ (arraysOf, read)
186import qualified Streamly.Internal.Data.Fold as FL
186import qualified Streamly.Internal.Data.Fold as FL
187 (Fold, Step(..), takeEndBy_, takeEndBy, catMaybes, take)
187 (Fold, Step(..), takeEndBy_, takeEndBy, catMaybes, take)
188import qualified Streamly.Internal.Data.IsMap as IsMap
188import qualified Streamly.Internal.Data.IsMap as IsMap
@@ -843,7 +843,7 @@ splitBySeq
843 :: (IsStream t, MonadAsync m, Unboxed a, Enum a, Eq a)
843 :: (IsStream t, MonadAsync m, Unboxed a, Enum a, Eq a)
844 => Array a -> Fold m a b -> t m a -> t m b
844 => Array a -> Fold m a b -> t m a -> t m b
845splitBySeq patt f m =
845splitBySeq patt f m =
846− intersperseM (fold f (A.toStream patt)) $ splitOnSeq patt f m
846+ intersperseM (fold f (A.read patt)) $ splitOnSeq patt f m
847
847
848-- | Like 'splitSuffixBy' but the separator is a sequence of elements, instead
848-- | Like 'splitSuffixBy' but the separator is a sequence of elements, instead
849-- of a predicate for a single element.
849-- of a predicate for a single element.
src/Streamly/Internal/Data/Stream/IsStream/Top.hs+4−4
@@ -68,7 +68,7 @@ import Streamly.Internal.Data.Time.Units (NanoSecond64(..), toRelTime64)
68import qualified Data.List as List
68import qualified Data.List as List
69import qualified Data.Map.Strict as Map
69import qualified Data.Map.Strict as Map
70import qualified Streamly.Internal.Data.Array as Array
70import qualified Streamly.Internal.Data.Array as Array
71− (fromStream, length, toStream)
71+ (fromStream, length, read)
72import qualified Streamly.Data.Array.Unboxed.Mut as MA
72import qualified Streamly.Data.Array.Unboxed.Mut as MA
73import qualified Streamly.Internal.Data.Fold as Fold
73import qualified Streamly.Internal.Data.Fold as Fold
74 (one, last, toStream, toStreamRev)
74 (one, last, toStream, toStreamRev)
@@ -498,8 +498,8 @@ joinOuter eq s1 s =
498 where
498 where
499
499
500 leftOver inputArr foundArr =
500 leftOver inputArr foundArr =
501− let stream1 = IsStream.fromSerial $ Array.toStream inputArr
501+ let stream1 = IsStream.fromSerial $ Array.read inputArr
502− stream2 = Stream.unfold MA.read foundArr
502+ stream2 = Stream.unfold MA.reader foundArr
503 in Stream.filter
503 in Stream.filter
504 isJust
504 isJust
505 ( Stream.zipWith (\x y ->
505 ( Stream.zipWith (\x y ->
@@ -521,7 +521,7 @@ joinOuter eq s1 s =
521 then Stream.nil
521 then Stream.nil
522 else Stream.fromPure Nothing
522 else Stream.fromPure Nothing
523 (i, b) <-
523 (i, b) <-
524− let stream = IsStream.fromSerial $ Array.toStream inputArr
524+ let stream = IsStream.fromSerial $ Array.read inputArr
525 in Stream.indexed $ fmap Just (Stream.liftInner stream) <> final
525 in Stream.indexed $ fmap Just (Stream.liftInner stream) <> final
526
526
527 case b of
527 case b of
src/Streamly/Internal/FileSystem/Event/Linux.hs+1−1
@@ -624,7 +624,7 @@ toUtf8 :: MonadIO m => String -> m (Array Word8)
624toUtf8 = A.fromStream . U.encodeUtf8 . S.fromList
624toUtf8 = A.fromStream . U.encodeUtf8 . S.fromList
625
625
626utf8ToString :: Array Word8 -> String
626utf8ToString :: Array Word8 -> String
627−utf8ToString = runIdentity . S.fold FL.toList . U.decodeUtf8' . A.toStream
627+utf8ToString = runIdentity . S.fold FL.toList . U.decodeUtf8' . A.read
628
628
629-- | Add a trailing "/" at the end of the path if there is none. Do not add a
629-- | Add a trailing "/" at the end of the path if there is none. Do not add a
630-- "/" if the path is empty.
630-- "/" if the path is empty.
src/Streamly/Internal/FileSystem/Event/Windows.hs+1−1
@@ -433,7 +433,7 @@ pathsToHandles paths cfg = do
433-------------------------------------------------------------------------------
433-------------------------------------------------------------------------------
434
434
435utf8ToString :: Array Word8 -> FilePath
435utf8ToString :: Array Word8 -> FilePath
436−utf8ToString = runIdentity . S.fold Fold.toList . U.decodeUtf8 . A.toStream
436+utf8ToString = runIdentity . S.fold Fold.toList . U.decodeUtf8 . A.read
437
437
438utf8ToStringList :: NonEmpty (Array Word8) -> NonEmpty FilePath
438utf8ToStringList :: NonEmpty (Array Word8) -> NonEmpty FilePath
439utf8ToStringList = NonEmpty.map utf8ToString
439utf8ToStringList = NonEmpty.map utf8ToString
src/Streamly/Internal/FileSystem/File.hs+1−1
@@ -295,7 +295,7 @@ readerWith = usingFile2 FH.readerWith
295-- /Pre-release/
295-- /Pre-release/
296{-# INLINE reader #-}
296{-# INLINE reader #-}
297reader :: (MonadCatch m, MonadAsync m) => Unfold m FilePath Word8
297reader :: (MonadCatch m, MonadAsync m) => Unfold m FilePath Word8
298−reader = UF.many A.read (usingFile FH.chunkReader)
298+reader = UF.many A.reader (usingFile FH.chunkReader)
299
299
300-- | Generate a stream of bytes from a file specified by path. The stream ends
300-- | Generate a stream of bytes from a file specified by path. The stream ends
301-- when EOF is encountered. File is locked using multiple reader and single
301-- when EOF is encountered. File is locked using multiple reader and single
src/Streamly/Internal/Network/Inet/TCP.hs+1−1
@@ -320,7 +320,7 @@ withConnection addr port =
320{-# INLINE reader #-}
320{-# INLINE reader #-}
321reader :: (MonadCatch m, MonadAsync m)
321reader :: (MonadCatch m, MonadAsync m)
322 => Unfold m ((Word8, Word8, Word8, Word8), PortNumber) Word8
322 => Unfold m ((Word8, Word8, Word8, Word8), PortNumber) Word8
323−reader = UF.many A.read (usingConnection ISK.chunkReader)
323+reader = UF.many A.reader (usingConnection ISK.chunkReader)
324
324
325-- | Read a stream from the supplied IPv4 host address and port number.
325-- | Read a stream from the supplied IPv4 host address and port number.
326--
326--
src/Streamly/Internal/Network/Socket.hs+2−2
@@ -95,7 +95,7 @@ import Streamly.Internal.Data.Unfold.Type (Unfold(..))
95-- import Streamly.String (encodeUtf8, decodeUtf8, foldLines)
95-- import Streamly.String (encodeUtf8, decodeUtf8, foldLines)
96import Streamly.Internal.System.IO (defaultChunkSize)
96import Streamly.Internal.System.IO (defaultChunkSize)
97
97
98−import qualified Streamly.Data.Array.Unboxed as A (read, length, writeN)
98+import qualified Streamly.Data.Array.Unboxed as A (reader, length, writeN)
99import qualified Streamly.Data.Fold as FL
99import qualified Streamly.Data.Fold as FL
100import qualified Streamly.Internal.Data.Array.Unboxed.Type as A
100import qualified Streamly.Internal.Data.Array.Unboxed.Type as A
101 (unsafeFreeze, asPtrUnsafe, byteLength, writeNUnsafe)
101 (unsafeFreeze, asPtrUnsafe, byteLength, writeNUnsafe)
@@ -433,7 +433,7 @@ read = readWith defaultChunkSize
433-- @since 0.9.0
433-- @since 0.9.0
434{-# INLINE readerWith #-}
434{-# INLINE readerWith #-}
435readerWith :: MonadIO m => Unfold m (Int, Socket) Word8
435readerWith :: MonadIO m => Unfold m (Int, Socket) Word8
436−readerWith = UF.many A.read chunkReaderWith
436+readerWith = UF.many A.reader chunkReaderWith
437
437
438-- | Same as 'readWith'
438-- | Same as 'readWith'
439--
439--
src/Streamly/Internal/Unicode/Utf8.hs+3−2
@@ -27,7 +27,8 @@ import Data.Word (Word8)
27import Streamly.Data.Array.Unboxed (Array)
27import Streamly.Data.Array.Unboxed (Array)
28import System.IO.Unsafe (unsafePerformIO)
28import System.IO.Unsafe (unsafePerformIO)
29
29
30−import qualified Streamly.Internal.Data.Array.Unboxed as Array (fromStreamN, toStream)
30+import qualified Streamly.Internal.Data.Array.Unboxed as Array
31+ (fromStreamN, read)
31import qualified Streamly.Internal.Data.Stream.IsStream as Stream
32import qualified Streamly.Internal.Data.Stream.IsStream as Stream
32import qualified Streamly.Internal.Unicode.Stream as Unicode
33import qualified Streamly.Internal.Unicode.Stream as Unicode
33
34
@@ -64,4 +65,4 @@ pack s =
64unpack :: Utf8 -> String
65unpack :: Utf8 -> String
65unpack u =
66unpack u =
66 unsafePerformIO
67 unsafePerformIO
67− $ Stream.toList $ Unicode.decodeUtf8' $ Array.toStream $ toArray u
68+ $ Stream.toList $ Unicode.decodeUtf8' $ Array.read $ toArray u
test/Streamly/Test/Data/Array.hs+5−3
@@ -20,10 +20,12 @@ moduleName = "Data.Array"
20#include "Streamly/Test/Data/Array/Common.hs"
20#include "Streamly/Test/Data/Array/Common.hs"
21
21
22testFromStreamToStream :: Property
22testFromStreamToStream :: Property
23+testFromStreamToStream =
23−testFromStreamToStream = genericTestFromTo (const A.fromStream) A.toStream (==)
24+ genericTestFromTo (const A.fromStream) A.read (==)
24
25
25testFoldUnfold :: Property
26testFoldUnfold :: Property
27+testFoldUnfold =
26−testFoldUnfold = genericTestFromTo (const (S.fold A.write)) (S.unfold A.read) (==)
28+ genericTestFromTo (const (S.fold A.write)) (S.unfold A.reader) (==)
27
29
28testFromList :: Property
30testFromList :: Property
29testFromList =
31testFromList =
@@ -31,7 +33,7 @@ testFromList =
31 forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
33 forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
32 monadicIO $ do
34 monadicIO $ do
33 let arr = A.fromList list
35 let arr = A.fromList list
34− xs <- run $ S.fold Fold.toList $ S.unfold A.read arr
36+ xs <- run $ S.fold Fold.toList $ S.unfold A.reader arr
35 assert (xs == list)
37 assert (xs == list)
36
38
37testLengthFromStream :: Property
39testLengthFromStream :: Property
test/Streamly/Test/Data/Array/Common.hs+8−7
@@ -53,24 +53,25 @@ genericTestFromTo arrFold arrUnfold listEq =
53
53
54testFoldNUnfold :: Property
54testFoldNUnfold :: Property
55testFoldNUnfold =
55testFoldNUnfold =
56− genericTestFromTo (S.fold . A.writeN) (S.unfold A.read) (==)
56+ genericTestFromTo (S.fold . A.writeN) (S.unfold A.reader) (==)
57
57
58testFoldNToStream :: Property
58testFoldNToStream :: Property
59testFoldNToStream =
59testFoldNToStream =
60− genericTestFromTo (S.fold . A.writeN) A.toStream (==)
60+ genericTestFromTo (S.fold . A.writeN) A.read (==)
61
61
62testFoldNToStreamRev :: Property
62testFoldNToStreamRev :: Property
63testFoldNToStreamRev =
63testFoldNToStreamRev =
64 genericTestFromTo
64 genericTestFromTo
65 (S.fold . A.writeN)
65 (S.fold . A.writeN)
66− A.toStreamRev
66+ A.readRev
67 (\xs list -> xs == reverse list)
67 (\xs list -> xs == reverse list)
68
68
69testFromStreamNUnfold :: Property
69testFromStreamNUnfold :: Property
70+testFromStreamNUnfold =
70−testFromStreamNUnfold = genericTestFromTo A.fromStreamN (S.unfold A.read) (==)
71+ genericTestFromTo A.fromStreamN (S.unfold A.reader) (==)
71
72
72testFromStreamNToStream :: Property
73testFromStreamNToStream :: Property
73−testFromStreamNToStream = genericTestFromTo A.fromStreamN A.toStream (==)
74+testFromStreamNToStream = genericTestFromTo A.fromStreamN A.read (==)
74
75
75testFromListN :: Property
76testFromListN :: Property
76testFromListN =
77testFromListN =
@@ -79,7 +80,7 @@ testFromListN =
79 forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
80 forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
80 monadicIO $ do
81 monadicIO $ do
81 let arr = A.fromListN n list
82 let arr = A.fromListN n list
82− xs <- run $ S.fold Fold.toList $ S.unfold A.read arr
83+ xs <- run $ S.fold Fold.toList $ S.unfold A.reader arr
83 listEquals (==) xs (take n list)
84 listEquals (==) xs (take n list)
84
85
85foldManyWith :: (Int -> Fold IO Int (Array Int)) -> Property
86foldManyWith :: (Int -> Fold IO Int (Array Int)) -> Property
@@ -89,7 +90,7 @@ foldManyWith f =
89 monadicIO $ do
90 monadicIO $ do
90 xs <- run
91 xs <- run
91 $ S.fold Fold.toList
92 $ S.fold Fold.toList
92− $ S.unfoldMany A.read
93+ $ S.unfoldMany A.reader
93 $ S.foldMany (f 240)
94 $ S.foldMany (f 240)
94 $ S.fromList list
95 $ S.fromList list
95 assert (xs == list)
96 assert (xs == list)
test/Streamly/Test/Data/Array/Unboxed.hs+4−3
@@ -38,10 +38,11 @@ moduleName = "Data.Array.Unboxed"
38#include "Streamly/Test/Data/Array/Common.hs"
38#include "Streamly/Test/Data/Array/Common.hs"
39
39
40testFromStreamToStream :: Property
40testFromStreamToStream :: Property
41−testFromStreamToStream = genericTestFromTo (const A.fromStream) A.toStream (==)
41+testFromStreamToStream = genericTestFromTo (const A.fromStream) A.read (==)
42
42
43testFoldUnfold :: Property
43testFoldUnfold :: Property
44+testFoldUnfold =
44−testFoldUnfold = genericTestFromTo (const (S.fold A.write)) (S.unfold A.read) (==)
45+ genericTestFromTo (const (S.fold A.write)) (S.unfold A.reader) (==)
45
46
46testFromList :: Property
47testFromList :: Property
47testFromList =
48testFromList =
@@ -49,7 +50,7 @@ testFromList =
49 forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
50 forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
50 monadicIO $ do
51 monadicIO $ do
51 let arr = A.fromList list
52 let arr = A.fromList list
52− xs <- run $ S.fold Fold.toList $ S.unfold A.read arr
53+ xs <- run $ S.fold Fold.toList $ S.unfold A.reader arr
53 assert (xs == list)
54 assert (xs == list)
54
55
55testLengthFromStream :: Property
56testLengthFromStream :: Property
test/Streamly/Test/FileSystem/Event/Common.hs+1−1
@@ -104,7 +104,7 @@ eventMatches ev (expectedPath, f) =
104
104
105 utf8ToString :: Array Word8 -> String
105 utf8ToString :: Array Word8 -> String
106 utf8ToString =
106 utf8ToString =
107− runIdentity . Stream.toList . Unicode.decodeUtf8' . Array.toStream
107+ runIdentity . Stream.toList . Unicode.decodeUtf8' . Array.read
108
108
109 evPath = utf8ToString (Event.getAbsPath ev)
109 evPath = utf8ToString (Event.getAbsPath ev)
110
110
test/Streamly/Test/FileSystem/Handle.hs+3−3
@@ -56,7 +56,7 @@ toList = Stream.fold Fold.toList
56
56
57utf8ToString :: Array.Array Word8 -> String
57utf8ToString :: Array.Array Word8 -> String
58utf8ToString =
58utf8ToString =
59− runIdentity . toList . Unicode.decodeUtf8' . Array.toStream
59+ runIdentity . toList . Unicode.decodeUtf8' . Array.read
60
60
61testData :: String
61testData :: String
62testData = "This is the test data for FileSystem.Handle ??`!@#$%^&*~~))`]"
62testData = "This is the test data for FileSystem.Handle ??`!@#$%^&*~~))`]"
@@ -89,7 +89,7 @@ readWithBufferFromHandle =
89readChunksFromHandle :: IO (Stream IO Char)
89readChunksFromHandle :: IO (Stream IO Char)
90readChunksFromHandle =
90readChunksFromHandle =
91 let f = Unicode.decodeUtf8
91 let f = Unicode.decodeUtf8
92− . Stream.concatMap Array.toStream
92+ . Stream.concatMap Array.read
93 . Stream.unfold Handle.chunkReader
93 . Stream.unfold Handle.chunkReader
94 in executor f
94 in executor f
95
95
@@ -98,7 +98,7 @@ readChunksWithBuffer =
98 let f1 = (\h -> (1024, h))
98 let f1 = (\h -> (1024, h))
99 f2 =
99 f2 =
100 Unicode.decodeUtf8
100 Unicode.decodeUtf8
101− . Stream.concatMap Array.toStream
101+ . Stream.concatMap Array.read
102 . Stream.unfold Handle.chunkReaderWith
102 . Stream.unfold Handle.chunkReaderWith
103 . f1
103 . f1
104 in executor f2
104 in executor f2