on master help sign in
Change the unfold/toStream naming for arrays (#2004)
commite8564258ec5309340f801261ca85c24c52d2d28d authorHarendra Kumar <harendra@composewell.com> dateThu 20 Oct 2022, 20:12 (4 years ago) parente03cceb
33 files changed+227−175
benchmark/Streamly/Benchmark/Data/Array/Common.hs+4−4 benchmark/Streamly/Benchmark/Data/Array/Stream/Unboxed.hs+1−1 benchmark/Streamly/Benchmark/Data/Array/Unboxed.hs+1−1 benchmark/Streamly/Benchmark/Data/Array/Unboxed/Mut.hs+5−5 benchmark/Streamly/Benchmark/FileSystem/Handle/Read.hs+1−1 benchmark/Streamly/Benchmark/FileSystem/Handle/ReadWrite.hs+2−2 benchmark/Streamly/Benchmark/Unicode/Char.hs+4−4 benchmark/Streamly/Benchmark/Unicode/Stream.hs+1−1 core/src/Streamly/Data/Array.hs+7−7 core/src/Streamly/Data/Array/Unboxed.hs+33−11 core/src/Streamly/Data/Array/Unboxed/Mut.hs+13−11 core/src/Streamly/Internal/Data/Array.hs+24−24 core/src/Streamly/Internal/Data/Array/Mut/Type.hs+7−9 core/src/Streamly/Internal/Data/Array/Unboxed.hs+25−16 core/src/Streamly/Internal/Data/Array/Unboxed/Mut/Type.hs+22−22 core/src/Streamly/Internal/Data/Array/Unboxed/Stream.hs+6−6 core/src/Streamly/Internal/Data/Array/Unboxed/Type.hs+24−8 core/src/Streamly/Internal/Data/Stream/Top.hs+3−3 core/src/Streamly/Internal/FileSystem/Handle.hs+6−6 core/src/Streamly/Internal/Unicode/Array/Char.hs+2−2 src/Streamly/Internal/Data/Stream/IsStream/Reduce.hs+2−2 src/Streamly/Internal/Data/Stream/IsStream/Top.hs+4−4 src/Streamly/Internal/FileSystem/Event/Linux.hs+1−1 src/Streamly/Internal/FileSystem/Event/Windows.hs+1−1 src/Streamly/Internal/FileSystem/File.hs+1−1 src/Streamly/Internal/Network/Inet/TCP.hs+1−1 src/Streamly/Internal/Network/Socket.hs+2−2 src/Streamly/Internal/Unicode/Utf8.hs+3−2 test/Streamly/Test/Data/Array.hs+5−3 test/Streamly/Test/Data/Array/Common.hs+8−7 test/Streamly/Test/Data/Array/Unboxed.hs+4−3 test/Streamly/Test/FileSystem/Event/Common.hs+1−1 test/Streamly/Test/FileSystem/Handle.hs+3−3
benchmark/Streamly/Benchmark/Data/Array/Common.hs+4−4
@@ -69,7 +69,7 @@ onArray
6969 :: MonadIO m => Int -> (Stream.Stream m Int -> Stream.Stream m Int)
7070 -> Stream Int
7171 -> 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
7373
7474scanl' value n = composeN n $ onArray value $ S.scanl' (+) 0
7575scanl1' value n = composeN n $ onArray value $ S.scanl1' (+)
@@ -98,7 +98,7 @@ showInstance = P.show
9898
9999{-# INLINE pureFoldl' #-}
100100pureFoldl' :: MonadIO m => Stream Int -> m Int
101−pureFoldl' = S.foldl' (+) 0 . S.unfold A.read
101+pureFoldl' = S.foldl' (+) 0 . S.unfold A.reader
102102
103103-------------------------------------------------------------------------------
104104-- Elimination
@@ -106,11 +106,11 @@ pureFoldl' = S.foldl' (+) 0 . S.unfold A.read
106106
107107{-# INLINE unfoldReadDrain #-}
108108unfoldReadDrain :: MonadIO m => Stream Int -> m ()
109−unfoldReadDrain = S.drain . S.unfold A.read
109+unfoldReadDrain = S.drain . S.unfold A.reader
110110
111111{-# INLINE toStreamRevDrain #-}
112112toStreamRevDrain :: MonadIO m => Stream Int -> m ()
113−toStreamRevDrain = S.drain . A.toStreamRev
113+toStreamRevDrain = S.drain . A.readRev
114114
115115-------------------------------------------------------------------------------
116116-- Bench groups
benchmark/Streamly/Benchmark/Data/Array/Stream/Unboxed.hs+1−1
@@ -108,7 +108,7 @@ inspect $ 'toChunksSumLengths `hasNoType` ''Step
108108-- | Sum the bytes in a file.
109109toChunksCountBytes :: Handle -> IO Word8
110110toChunksCountBytes 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
112112 let s = Handle.readChunks inh
113113 Stream.foldl' (\acc arr -> acc + foldlArr' (+) 0 arr) 0 s
114114
benchmark/Streamly/Benchmark/Data/Array/Unboxed.hs+1−1
@@ -7,7 +7,7 @@ import Control.DeepSeq (deepseq)
77import qualified Streamly.Internal.Data.Array.Unboxed as IA
88import qualified GHC.Exts as GHC
99
10−import qualified Streamly.Data.Array.Unboxed as A
10+-- import qualified Streamly.Data.Array.Unboxed as A
1111import qualified Streamly.Internal.Data.Array.Unboxed as A
1212type Stream = A.Array
1313
benchmark/Streamly/Benchmark/Data/Array/Unboxed/Mut.hs+5−5
@@ -158,7 +158,7 @@ onArray
158158 -> Stream Int
159159 -> m (Stream Int)
160160onArray 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
162162
163163-------------------------------------------------------------------------------
164164-- Elimination
@@ -166,11 +166,11 @@ onArray value f arr =
166166
167167{-# INLINE unfoldReadDrain #-}
168168unfoldReadDrain :: MonadIO m => Stream Int -> m ()
169−unfoldReadDrain = drain . Stream.unfold MArray.read
169+unfoldReadDrain = drain . Stream.unfold MArray.reader
170170
171171{-# INLINE unfoldReadRevDrain #-}
172172unfoldReadRevDrain :: MonadIO m => Stream Int -> m ()
173−unfoldReadRevDrain = drain . Stream.unfold MArray.readRev
173+unfoldReadRevDrain = drain . Stream.unfold MArray.readerRev
174174
175175{-# INLINE toStreamDRevDrain #-}
176176toStreamDRevDrain :: MonadIO m => Stream Int -> m ()
@@ -183,7 +183,7 @@ toStreamDDrain = drain . Stream.fromStreamD . MArray.toStreamD
183183
184184{-# INLINE unfoldFold #-}
185185unfoldFold :: 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
187187
188188-------------------------------------------------------------------------------
189189-- Bench groups
@@ -260,7 +260,7 @@ o_1_space_serial_marray value ~(array, indices) =
260260 $ MArray.strip (> 0)
261261 , benchIO' "modifyIndices (+ 1)" (const (return indices))
262262 $ Stream.fold (MArray.modifyIndices (\_idx val -> val + 1) array)
263− . Stream.unfold Array.read
263+ . Stream.unfold Array.reader
264264 ]
265265
266266-------------------------------------------------------------------------------
benchmark/Streamly/Benchmark/FileSystem/Handle/Read.hs+1−1
@@ -189,7 +189,7 @@ getChunksConcatUnfoldCountLines inh =
189189 $ IUS.lines FL.drain
190190 $ SS.decodeLatin1
191191 -- XXX replace with toBytes
192− $ S.unfoldMany A.read (IFH.readChunks inh)
192+ $ S.unfoldMany A.reader (IFH.readChunks inh)
193193
194194#ifdef INSPECTION
195195inspect $ hasNoTypeClasses 'getChunksConcatUnfoldCountLines
benchmark/Streamly/Benchmark/FileSystem/Handle/ReadWrite.hs+2−2
@@ -134,7 +134,7 @@ _readChunks inh devNull = IUF.fold fld unf inh
134134 where
135135
136136 fld = FH.write devNull
137− unf = IUF.many A.read FH.chunkReader
137+ unf = IUF.many A.reader FH.chunkReader
138138
139139-- | Send the chunk content to /dev/null
140140-- Implicitly benchmarked via 'readWithFromBytesNull'
@@ -144,7 +144,7 @@ _readChunksWith inh devNull = IUF.fold fld unf (defaultChunkSize, inh)
144144 where
145145
146146 fld = FH.write devNull
147− unf = IUF.many A.read FH.chunkReaderWith
147+ unf = IUF.many A.reader FH.chunkReaderWith
148148
149149o_1_space_copy_fromBytes :: BenchEnv -> [Benchmark]
150150o_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)
6565
6666benchFunctions :: [(String, Array Char -> IO ())]
6767benchFunctions =
68− [ ("NFD", IsStream.drain . normalize NFD . Array.toStream)
69− , ("NFKD", IsStream.drain . normalize NFKD . Array.toStream)
70− , ("NFC", IsStream.drain . normalize NFC . Array.toStream)
71− , ("NFKC", IsStream.drain . normalize NFKC . Array.toStream)
68+ [ ("NFD", IsStream.drain . normalize NFD . Array.read)
69+ , ("NFKD", IsStream.drain . normalize NFKD . Array.read)
70+ , ("NFC", IsStream.drain . normalize NFC . Array.read)
71+ , ("NFKC", IsStream.drain . normalize NFKC . Array.read)
7272 ]
7373
7474main :: IO ()
benchmark/Streamly/Benchmark/Unicode/Stream.hs+1−1
@@ -87,7 +87,7 @@ linesUnlinesCopy inh outh =
8787linesUnlinesArrayWord8Copy :: Handle -> Handle -> IO ()
8888linesUnlinesArrayWord8Copy inh outh =
8989 Stream.fold (Handle.write outh)
90− $ Stream.interposeSuffix 10 Array.read
90+ $ Stream.interposeSuffix 10 Array.reader
9191 $ Stream.splitOnSuffix (== 10) Array.write
9292 $ Stream.unfold Handle.reader inh
9393
core/src/Streamly/Data/Array.hs+7−7
@@ -22,19 +22,19 @@ module Streamly.Data.Array
2222 , A.writeN
2323 , A.write
2424
25− -- * Elimination
26−
27− , A.toStream
28− , A.toStreamRev
25+ -- * Streams
2926 , A.read
27+ , A.readRev
28+
29+ -- * Unfolds
30+ , A.reader
3031
3132 -- * Random Access
33+ , A.length
3234
3335 -- * Folding Arrays
34− , A.streamFold
36+ -- , A.streamFold
3537 , A.fold
36−
37− , A.length
3838 )
3939where
4040
core/src/Streamly/Data/Array/Unboxed.hs+33−11
@@ -1,5 +1,3 @@
1−#include "inline.hs"
2−
31-- |
42-- Module : Streamly.Data.Array.Unboxed
53-- Copyright : (c) 2019 Composewell Technologies
@@ -53,11 +51,11 @@
5351
5452module Streamly.Data.Array.Unboxed
5553 (
54+ -- * Types
5655 Unbox (..)
5756 , A.Array
5857
59− -- * Arrays
60− -- ** Construction
58+ -- * Construction
6159 -- | When performance matters, the fastest way to generate an array is
6260 -- 'writeN'. 'IsList' and 'IsString' instances can be
6361 -- used to conveniently construct arrays from literal values.
@@ -74,27 +72,37 @@ module Streamly.Data.Array.Unboxed
7472 , A.write -- full buffer
7573 , writeLastN -- drop old (ring buffer)
7674
77− -- ** Elimination
75+ -- * Conversion
7876 -- 'GHC.Exts.toList' from "GHC.Exts" can be used to convert an array to a
7977 -- list.
80−
8178 , A.toList
82− , A.read
83− , A.readRev
8479
85− -- ** Casting
80+ -- * Unfolds
81+ , A.reader
82+ , A.readerRev
83+
84+ -- * Casting
8685 , cast
8786 , asBytes
8887
89− -- ** Random Access
88+ -- * Random Access
9089 , A.length
9190 -- , (!!)
9291 , A.getIndex
92+
93+ -- * Deprecated
94+ , read
95+ , readRev
9396 )
9497where
9598
96−import Streamly.Internal.Data.Array.Unboxed as A
99+#include "inline.hs"
100+
101+import Streamly.Internal.Data.Unfold (Unfold)
102+import Streamly.Internal.Data.Array.Unboxed as A hiding (read, readRev)
103+
97104import Streamly.Internal.Data.Unboxed (Unbox (..))
105+import Prelude hiding (read)
98106
99107-- $setup
100108-- >>> :m
@@ -104,3 +112,17 @@ import Streamly.Internal.Data.Unboxed (Unbox (..))
104112-- >>> import Streamly.Data.Array.Unboxed (Array)
105113-- >>> import qualified Streamly.Internal.Data.Stream as Stream
106114-- >>> 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 @@
1313
1414module Streamly.Data.Array.Unboxed.Mut
1515 (
16+ -- * Types
1617 Unbox (..)
1718 , Array
1819
19− -- * Arrays
20− -- ** Construction
20+ -- * Construction
2121
2222 -- Uninitialized Arrays
2323 , new
@@ -30,29 +30,31 @@ module Streamly.Data.Array.Unboxed.Mut
3030 , write -- full buffer
3131 -- writeLastN
3232
33− -- ** Appending elements
33+ -- * Appending elements
3434 , snoc
3535
36− -- ** Appending streams
36+ -- * Appending streams
3737 , appendN
3838 , append
3939
40− -- ** Inplace mutation
40+ -- * Inplace mutation
4141 , putIndex
4242
43− -- ** Random access
43+ -- * Random access
4444 , getIndex
4545
46− -- ** Elimination
46+ -- * Conversion
4747 , toList
48− , read
49− , readRev
5048
51− -- ** Casting
49+ -- * Unfolds
50+ , reader
51+ , readerRev
52+
53+ -- * Casting
5254 , cast
5355 , asBytes
5456
55− -- ** Size
57+ -- * Size
5658 , length
5759 )
5860where
core/src/Streamly/Internal/Data/Array.hs+24−24
@@ -30,13 +30,13 @@ module Streamly.Internal.Data.Array
3030
3131 -- * Elimination
3232 , length
33− , read
33+ , reader
3434
3535 , toList
36− , toStreamD
37− , toStreamDRev
38− , toStream
39− , toStreamRev
36+ , readStreamD
37+ , readRevStreamD
38+ , read
39+ , readRev
4040
4141 , foldl'
4242 , foldr
@@ -173,9 +173,9 @@ fromList xs = unsafePerformIO $ fromStreamD $ D.fromList xs
173173length :: Array a -> Int
174174length = arrLen
175175
176−{-# INLINE_NORMAL read #-}
177−read :: MonadIO m => Unfold m (Array a) a
178−read = Unfold.lmap unsafeThaw MArray.read
176+{-# INLINE_NORMAL reader #-}
177+reader :: MonadIO m => Unfold m (Array a) a
178+reader = Unfold.lmap unsafeThaw MArray.reader
179179
180180-------------------------------------------------------------------------------
181181-- Elimination - to streams
@@ -191,23 +191,23 @@ toList arr = loop 0
191191 loop i | i == len = []
192192 loop i = getIndexUnsafe arr i : loop (i + 1)
193193
194−{-# INLINE_NORMAL toStreamD #-}
195−toStreamD :: MonadIO m => Array a -> D.Stream m a
196−toStreamD = MArray.toStreamD . unsafeThaw
194+{-# INLINE_NORMAL readStreamD #-}
195+readStreamD :: MonadIO m => Array a -> D.Stream m a
196+readStreamD = MArray.toStreamD . unsafeThaw
197197
198−{-# INLINE_NORMAL toStreamDRev #-}
199−toStreamDRev :: Monad m => Array a -> D.Stream m a
200−toStreamDRev arr@Array{..} =
198+{-# INLINE_NORMAL readRevStreamD #-}
199+readRevStreamD :: Monad m => Array a -> D.Stream m a
200+readRevStreamD arr@Array{..} =
201201 D.map (getIndexUnsafe arr)
202202 $ D.enumerateFromThenToIntegral (arrLen - 1) (arrLen - 2) 0
203203
204−{-# INLINE_EARLY toStream #-}
205−toStream :: MonadIO m => Array a -> Stream m a
206−toStream = Stream.fromStreamD . toStreamD
204+{-# INLINE_EARLY read #-}
205+read :: MonadIO m => Array a -> Stream m a
206+read = Stream.fromStreamD . readStreamD
207207
208−{-# INLINE_EARLY toStreamRev #-}
209−toStreamRev :: Monad m => Array a -> Stream m a
210−toStreamRev = Stream.fromStreamD . toStreamDRev
208+{-# INLINE_EARLY readRev #-}
209+readRev :: Monad m => Array a -> Stream m a
210+readRev = Stream.fromStreamD . readRevStreamD
211211
212212-------------------------------------------------------------------------------
213213-- Elimination - using Folds
@@ -215,11 +215,11 @@ toStreamRev = Stream.fromStreamD . toStreamDRev
215215
216216{-# INLINE_NORMAL foldl' #-}
217217foldl' :: (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
219219
220220{-# INLINE_NORMAL foldr #-}
221221foldr :: (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
223223
224224instance NFData a => NFData (Array a) where
225225 {-# INLINE rnf #-}
@@ -227,11 +227,11 @@ instance NFData a => NFData (Array a) where
227227
228228{-# INLINE fold #-}
229229fold :: 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)
231231
232232{-# INLINE streamFold #-}
233233streamFold :: 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)
235235
236236-------------------------------------------------------------------------------
237237-- 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
8484
8585 -- * Eliminating and Reading
8686
87− -- ** To streams
88− , read
89− -- , readRev
87+ -- ** Unfolds
88+ , reader
89+ -- , readerRev
90+ , producer -- experimental
9091
9192 -- ** To containers
9293 , toStreamD
@@ -95,9 +96,6 @@ module Streamly.Internal.Data.Array.Mut.Type
9596 -- , toStreamKRev
9697 , toList
9798
98− -- experimental
99− , producer
100−
10199 -- ** Random reads
102100 , getIndex
103101 , getIndexUnsafe
@@ -570,9 +568,9 @@ producer = Producer step inject extract
570568
571569-- | Unfold an array into a stream.
572570--
573−{-# INLINE_NORMAL read #-}
574−read :: MonadIO m => Unfold m (Array a) a
575−read = Producer.simplify producer
571+{-# INLINE_NORMAL reader #-}
572+reader :: MonadIO m => Unfold m (Array a) a
573+reader = Producer.simplify producer
576574
577575--------------------------------------------------------------------------------
578576-- Appending arrays
core/src/Streamly/Internal/Data/Array/Unboxed.hs+25−16
@@ -49,12 +49,17 @@ module Streamly.Internal.Data.Array.Unboxed
4949 , writeLastN
5050
5151 -- * Elimination
52+ -- ** Conversion
5253 , A.toList
53− , A.toStream
54− , A.toStreamRev
55− , read
56− , unsafeRead -- XXX readUnsafe?
54+
55+ -- ** Streams
56+ , A.read
5757 , A.readRev
58+
59+ -- ** Unfolds
60+ , reader
61+ , readerUnsafe
62+ , A.readerRev
5863 , producer -- experimental
5964
6065 -- * Random Access
@@ -103,6 +108,10 @@ module Streamly.Internal.Data.Array.Unboxed
103108 -- ** Folding
104109 , streamFold
105110 , fold
111+
112+ -- * Deprecated
113+ , A.toStream
114+ , A.toStreamRev
106115 )
107116where
108117
@@ -187,12 +196,10 @@ producer =
187196
188197-- | Unfold an array into a stream.
189198--
190−-- /Since 0.7.0 (Streamly.Memory.Array)/
191−--
192−-- @since 0.8.0
193−{-# INLINE_NORMAL read #-}
194−read :: forall m a. (Monad m, Unboxed a) => Unfold m (Array a) a
195−read = Producer.simplify producer
199+-- @since 0.9.0
200+{-# INLINE_NORMAL reader #-}
201+reader :: forall m a. (Monad m, Unboxed a) => Unfold m (Array a) a
202+reader = Producer.simplify producer
196203
197204-- | Unfold an array into a stream, does not check the end of the array, the
198205-- user is responsible for terminating the stream within the array bounds. For
@@ -205,9 +212,9 @@ read = Producer.simplify producer
205212--
206213-- /Pre-release/
207214--
208−{-# INLINE_NORMAL unsafeRead #-}
209−unsafeRead :: forall m a. (Monad m, Unboxed a) => Unfold m (Array a) a
210−unsafeRead = Unfold step inject
215+{-# INLINE_NORMAL readerUnsafe #-}
216+readerUnsafe :: forall m a. (Monad m, Unboxed a) => Unfold m (Array a) a
217+readerUnsafe = Unfold step inject
211218 where
212219
213220 inject (Array contents start end) =
@@ -484,7 +491,7 @@ runPipe f arr = P.runPipe (toArrayMinChunk (length arr)) $ f (A.read arr)
484491streamTransform :: forall m a b. (MonadIO m, Unboxed a, Unboxed b)
485492 => (Stream m a -> Stream m b) -> Array a -> m (Array b)
486493streamTransform 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)
488495
489496-------------------------------------------------------------------------------
490497-- Casts
@@ -544,16 +551,18 @@ asCStringUnsafe arr act = do
544551-- Folds
545552-------------------------------------------------------------------------------
546553
554+-- XXX We can directly use toStreamD and D.fold here.
555+
547556-- | Fold an array using a 'Fold'.
548557--
549558-- /Pre-release/
550559{-# INLINE fold #-}
551560fold :: 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))
553562
554563-- | Fold an array using a stream fold operation.
555564--
556565-- /Pre-release/
557566{-# INLINE streamFold #-}
558567streamFold :: (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
9696 -- * Eliminating and Reading
9797
9898 -- ** To streams
99− , read
100− , readRevWith
101− , readRev
99+ , reader
100+ , readerRevWith
101+ , readerRev
102102
103103 -- ** To containers
104104 , toStreamDWith
@@ -1088,7 +1088,7 @@ getSlice index len (Array contents start e _) =
10881088-- XXX consider the bulk update/accumulation/permutation APIs from vector.
10891089
10901090-- | 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
10921092-- to another array. However, in-place reverse can be useful to take adavantage
10931093-- of cache locality and when you do not want to allocate additional memory.
10941094--
@@ -1350,9 +1350,9 @@ data FlattenState s contents a =
13501350 OuterLoop s
13511351 | InnerLoop s contents !Int !Int
13521352
1353−-- | Use the "read" unfold instead.
1353+-- | Use the "reader" unfold instead.
13541354--
1355−-- @flattenArrays = unfoldMany read@
1355+-- @flattenArrays = unfoldMany reader@
13561356--
13571357-- We can try this if there are any fusion issues in the unfold.
13581358--
@@ -1379,9 +1379,9 @@ flattenArrays (D.Stream step state) = D.Stream step' (OuterLoop state)
13791379 x <- liftIO $ peekWith contents p
13801380 return $ D.Yield x (InnerLoop st contents (INDEX_NEXT(p,a)) end)
13811381
1382−-- | Use the "readRev" unfold instead.
1382+-- | Use the "readerRev" unfold instead.
13831383--
1384−-- @flattenArrays = unfoldMany readRev@
1384+-- @flattenArrays = unfoldMany readerRev@
13851385--
13861386-- We can try this if there are any fusion issues in the unfold.
13871387--
@@ -1459,15 +1459,15 @@ producer = producerWith liftIO
14591459-- | Unfold an array into a stream.
14601460--
14611461-- @since 0.7.0
1462−{-# INLINE_NORMAL read #-}
1463−read :: forall m a. (MonadIO m, Unboxed a) => Unfold m (Array a) a
1464−read = Producer.simplify producer
1462+{-# INLINE_NORMAL reader #-}
1463+reader :: forall m a. (MonadIO m, Unboxed a) => Unfold m (Array a) a
1464+reader = Producer.simplify producer
14651465
1466−{-# INLINE_NORMAL readRevWith #-}
1467−readRevWith ::
1466+{-# INLINE_NORMAL readerRevWith #-}
1467+readerRevWith ::
14681468 forall m a. (Monad m, Unboxed a)
14691469 => (forall b. IO b -> m b) -> Unfold m (Array a) a
1470−readRevWith liftio = Unfold step inject
1470+readerRevWith liftio = Unfold step inject
14711471 where
14721472
14731473 inject (Array contents start end _) =
@@ -1483,9 +1483,9 @@ readRevWith liftio = Unfold step inject
14831483-- | Unfold an array into a stream in reverse order.
14841484--
14851485-- /Pre-release/
1486−{-# INLINE_NORMAL readRev #-}
1487−readRev :: forall m a. (MonadIO m, Unboxed a) => Unfold m (Array a) a
1488−readRev = readRevWith liftIO
1486+{-# INLINE_NORMAL readerRev #-}
1487+readerRev :: forall m a. (MonadIO m, Unboxed a) => Unfold m (Array a) a
1488+readerRev = readerRevWith liftIO
14891489
14901490-------------------------------------------------------------------------------
14911491-- to Lists and streams
@@ -1543,9 +1543,9 @@ toStreamDWith liftio Array{..} = D.Stream step arrStart
15431543 r <- peekWith arrContents p
15441544 return $ D.Yield r (INDEX_NEXT(p,a))
15451545
1546−-- | Use the 'read' unfold instead.
1546+-- | Use the 'reader' unfold instead.
15471547--
1548−-- @toStreamD = D.unfold read@
1548+-- @toStreamD = D.unfold reader@
15491549--
15501550-- We can try this if the unfold has any performance issues.
15511551{-# INLINE_NORMAL toStreamD #-}
@@ -1585,9 +1585,9 @@ toStreamDRevWith liftio Array{..} =
15851585 r <- peekWith arrContents p
15861586 return $ D.Yield r (INDEX_PREV(p,a))
15871587
1588−-- | Use the 'readRev' unfold instead.
1588+-- | Use the 'readerRev' unfold instead.
15891589--
1590−-- @toStreamDRev = D.unfold readRev@
1590+-- @toStreamDRev = D.unfold readerRev@
15911591--
15921592-- We can try this if the unfold has any perf issues.
15931593{-# INLINE_NORMAL toStreamDRev #-}
@@ -1970,7 +1970,7 @@ fromArrayStreamK :: (Unboxed a, MonadIO m) =>
19701970 K.Stream m (Array a) -> m (Array a)
19711971fromArrayStreamK as = do
19721972 len <- arrayStreamKLength as
1973− fromStreamDN len $ D.unfoldMany read $ D.fromStreamK as
1973+ fromStreamDN len $ D.unfoldMany reader $ D.fromStreamK as
19741974
19751975-- CAUTION: a very large number (millions) of arrays can degrade performance
19761976-- 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)
130130concat :: (Monad m, Unboxed a) => Stream m (Array a) -> Stream m a
131131-- concat m = fromStreamD $ A.flattenArrays (toStreamD m)
132132-- 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)
134134
135135-- | Convert a stream of arrays into a stream of their elements reversing the
136136-- contents of each array before flattening.
137137--
138−-- > concatRev = Stream.unfoldMany Array.readRev
138+-- > concatRev = Stream.unfoldMany Array.readerRev
139139--
140140-- @since 0.7.0
141141{-# INLINE concatRev #-}
142142concatRev :: (Monad m, Unboxed a) => Stream m (Array a) -> Stream m a
143143-- 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)
145145
146146-------------------------------------------------------------------------------
147147-- Intersperse and append
@@ -153,12 +153,12 @@ concatRev m = fromStreamD $ D.unfoldMany A.readRev (toStreamD m)
153153-- /Pre-release/
154154{-# INLINE interpose #-}
155155interpose :: (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
157157
158158{-# INLINE intercalateSuffix #-}
159159intercalateSuffix :: (Monad m, Unboxed a)
160160 => Array a -> Stream m (Array a) -> Stream m a
161−intercalateSuffix = S.intercalateSuffix A.read
161+intercalateSuffix = S.intercalateSuffix A.reader
162162
163163-- | Flatten a stream of arrays appending the given element after each
164164-- array.
@@ -168,7 +168,7 @@ intercalateSuffix = S.intercalateSuffix A.read
168168interposeSuffix :: (Monad m, Unboxed a)
169169 => a -> Stream m (Array a) -> Stream m a
170170-- interposeSuffix x = fromStreamD . A.unlines x . toStreamD
171−interposeSuffix x = S.interposeSuffix x A.read
171+interposeSuffix x = S.interposeSuffix x A.reader
172172
173173data FlattenState s a =
174174 OuterLoop s
core/src/Streamly/Internal/Data/Array/Unboxed/Type.hs+24−8
@@ -39,7 +39,7 @@ module Streamly.Internal.Data.Array.Unboxed.Type
3939
4040 -- * Elimination
4141 , unsafeIndexIO
42− , unsafeIndex
42+ , unsafeIndex -- getIndexUnsafe
4343 , byteLength
4444 , length
4545
@@ -47,13 +47,15 @@ module Streamly.Internal.Data.Array.Unboxed.Type
4747 , foldr
4848 , splitAt
4949
50− , readRev
5150 , toStreamD
5251 , toStreamDRev
5352 , toStreamK
5453 , toStreamKRev
5554 , toStream
5655 , toStreamRev
56+ , read
57+ , readRev
58+ , readerRev
5759 , toList
5860
5961 -- * Folds
@@ -341,10 +343,10 @@ length arr = MA.length (unsafeThaw arr)
341343
342344-- | Unfold an array into a stream in reverse order.
343345--
344−-- @since 0.8.0
345−{-# INLINE_NORMAL readRev #-}
346−readRev :: forall m a. (Monad m, Unboxed a) => Unfold m (Array a) a
347−readRev = Unfold.lmap unsafeThaw $ MA.readRevWith (return . unsafeInlineIO)
346+-- @since 0.9.0
347+{-# INLINE_NORMAL readerRev #-}
348+readerRev :: forall m a. (Monad m, Unboxed a) => Unfold m (Array a) a
349+readerRev = Unfold.lmap unsafeThaw $ MA.readerRevWith (return . unsafeInlineIO)
348350
349351{-# INLINE_NORMAL toStreamD #-}
350352toStreamD :: forall m a. (Monad m, Unboxed a) => Array a -> D.Stream m a
@@ -367,9 +369,16 @@ toStreamKRev arr =
367369-- | Convert an 'Array' into a stream.
368370--
369371-- /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." #-}
370379{-# INLINE_EARLY toStream #-}
371380toStream :: (Monad m, Unboxed a) => Array a -> Stream m a
372−toStream = Stream.fromStreamD . toStreamD
381+toStream = read
373382-- XXX add fallback to StreamK rule
374383-- {-# RULES "Streamly.Array.read fallback to StreamK" [1]
375384-- forall a. S.readK (read a) = K.fromArray a #-}
@@ -377,9 +386,16 @@ toStream = Stream.fromStreamD . toStreamD
377386-- | Convert an 'Array' into a stream in reverse order.
378387--
379388-- /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." #-}
380396{-# INLINE_EARLY toStreamRev #-}
381397toStreamRev :: (Monad m, Unboxed a) => Array a -> Stream m a
382−toStreamRev = Stream.fromStreamD . toStreamDRev
398+toStreamRev = readRev
383399
384400-- XXX add fallback to StreamK rule
385401-- {-# 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 =
376376 where
377377
378378 leftOver inputArr foundArr =
379− let stream1 = Array.toStream inputArr
380− stream2 = Stream.unfold MA.read foundArr
379+ let stream1 = Array.read inputArr
380+ stream2 = Stream.unfold MA.reader foundArr
381381 in Stream.filter
382382 isJust
383383 ( Stream.zipWith (\x y ->
@@ -399,7 +399,7 @@ joinOuter eq s1 s =
399399 then Stream.nil
400400 else Stream.fromPure Nothing
401401 (i, b) <-
402− let stream = Array.toStream inputArr
402+ let stream = Array.read inputArr
403403 in Stream.indexed $ fmap Just (Stream.liftInner stream) <> final
404404
405405 case b of
core/src/Streamly/Internal/FileSystem/Handle.hs+6−6
@@ -332,12 +332,12 @@ chunkReader = UF.first defaultChunkSize chunkReaderWith
332332-- | Unfolds the tuple @(bufsize, handle)@ into a byte stream, read requests
333333-- to the IO device are performed using buffers of @bufsize@.
334334--
335−-- >>> readerWith = Unfold.many Array.read Handle.chunkReaderWith
335+-- >>> readerWith = Unfold.many Array.reader Handle.chunkReaderWith
336336--
337337-- @since 0.9.0
338338{-# INLINE readerWith #-}
339339readerWith :: MonadIO m => Unfold m (Int, Handle) Word8
340−readerWith = UF.many A.read chunkReaderWith
340+readerWith = UF.many A.reader chunkReaderWith
341341
342342-- | Same as 'readerWith'
343343--
@@ -350,7 +350,7 @@ readWithBufferOf = readerWith
350350-- | @readWith bufsize handle@ reads a byte stream from a file
351351-- handle, reads are performed in chunks of up to @bufsize@.
352352--
353−-- >>> readWith size h = Stream.unfoldMany Array.read $ Handle.readChunksWith size h
353+-- >>> readWith size h = Stream.unfoldMany Array.reader $ Handle.readChunksWith size h
354354--
355355-- /Pre-release/
356356{-# INLINE readWith #-}
@@ -361,16 +361,16 @@ readWith size h = AS.concat $ readChunksWith size h
361361-- performed in sizes of
362362-- 'Streamly.Internal.Data.Array.Unboxed.Type.defaultChunkSize'.
363363--
364−-- >>> reader = Unfold.many Array.read chunkReader
364+-- >>> reader = Unfold.many Array.reader chunkReader
365365--
366366-- @since 0.9.0
367367{-# INLINE reader #-}
368368reader :: MonadIO m => Unfold m Handle Word8
369−reader = UF.many A.read chunkReader
369+reader = UF.many A.reader chunkReader
370370
371371-- | Generate a byte stream from a file 'Handle'.
372372--
373−-- >>> read h = Stream.unfoldMany Array.read $ Handle.readChunks h
373+-- >>> read h = Stream.unfoldMany Array.reader $ Handle.readChunks h
374374--
375375-- /Pre-release/
376376{-# INLINE read #-}
core/src/Streamly/Internal/Unicode/Array/Char.hs+2−2
@@ -72,7 +72,7 @@ words = S.words A.write
7272-- > unlines . lines /= id
7373{-# INLINE unlines #-}
7474unlines :: MonadIO m => Stream m (Array Char) -> Stream m Char
75−unlines = S.unlines A.read
75+unlines = S.unlines A.reader
7676
7777-- | Flattens the stream of @Array Char@, after appending a separating
7878-- space to each string.
@@ -89,4 +89,4 @@ unlines = S.unlines A.read
8989-- > unwords . words /= id
9090{-# INLINE unwords #-}
9191unwords :: 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)
182182import qualified Data.Heap as H
183183import qualified Streamly.Data.Unfold as Unfold
184184import qualified Streamly.Internal.Data.Array.Unboxed.Type as A
185− (arraysOf, toStream)
185+ (arraysOf, read)
186186import qualified Streamly.Internal.Data.Fold as FL
187187 (Fold, Step(..), takeEndBy_, takeEndBy, catMaybes, take)
188188import qualified Streamly.Internal.Data.IsMap as IsMap
@@ -843,7 +843,7 @@ splitBySeq
843843 :: (IsStream t, MonadAsync m, Unboxed a, Enum a, Eq a)
844844 => Array a -> Fold m a b -> t m a -> t m b
845845splitBySeq 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
847847
848848-- | Like 'splitSuffixBy' but the separator is a sequence of elements, instead
849849-- 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)
6868import qualified Data.List as List
6969import qualified Data.Map.Strict as Map
7070import qualified Streamly.Internal.Data.Array as Array
71− (fromStream, length, toStream)
71+ (fromStream, length, read)
7272import qualified Streamly.Data.Array.Unboxed.Mut as MA
7373import qualified Streamly.Internal.Data.Fold as Fold
7474 (one, last, toStream, toStreamRev)
@@ -498,8 +498,8 @@ joinOuter eq s1 s =
498498 where
499499
500500 leftOver inputArr foundArr =
501− let stream1 = IsStream.fromSerial $ Array.toStream inputArr
502− stream2 = Stream.unfold MA.read foundArr
501+ let stream1 = IsStream.fromSerial $ Array.read inputArr
502+ stream2 = Stream.unfold MA.reader foundArr
503503 in Stream.filter
504504 isJust
505505 ( Stream.zipWith (\x y ->
@@ -521,7 +521,7 @@ joinOuter eq s1 s =
521521 then Stream.nil
522522 else Stream.fromPure Nothing
523523 (i, b) <-
524− let stream = IsStream.fromSerial $ Array.toStream inputArr
524+ let stream = IsStream.fromSerial $ Array.read inputArr
525525 in Stream.indexed $ fmap Just (Stream.liftInner stream) <> final
526526
527527 case b of
src/Streamly/Internal/FileSystem/Event/Linux.hs+1−1
@@ -624,7 +624,7 @@ toUtf8 :: MonadIO m => String -> m (Array Word8)
624624toUtf8 = A.fromStream . U.encodeUtf8 . S.fromList
625625
626626utf8ToString :: 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
628628
629629-- | Add a trailing "/" at the end of the path if there is none. Do not add a
630630-- "/" if the path is empty.
src/Streamly/Internal/FileSystem/Event/Windows.hs+1−1
@@ -433,7 +433,7 @@ pathsToHandles paths cfg = do
433433-------------------------------------------------------------------------------
434434
435435utf8ToString :: 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
437437
438438utf8ToStringList :: NonEmpty (Array Word8) -> NonEmpty FilePath
439439utf8ToStringList = NonEmpty.map utf8ToString
src/Streamly/Internal/FileSystem/File.hs+1−1
@@ -295,7 +295,7 @@ readerWith = usingFile2 FH.readerWith
295295-- /Pre-release/
296296{-# INLINE reader #-}
297297reader :: (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)
299299
300300-- | Generate a stream of bytes from a file specified by path. The stream ends
301301-- 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 =
320320{-# INLINE reader #-}
321321reader :: (MonadCatch m, MonadAsync m)
322322 => 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)
324324
325325-- | Read a stream from the supplied IPv4 host address and port number.
326326--
src/Streamly/Internal/Network/Socket.hs+2−2
@@ -95,7 +95,7 @@ import Streamly.Internal.Data.Unfold.Type (Unfold(..))
9595-- import Streamly.String (encodeUtf8, decodeUtf8, foldLines)
9696import Streamly.Internal.System.IO (defaultChunkSize)
9797
98−import qualified Streamly.Data.Array.Unboxed as A (read, length, writeN)
98+import qualified Streamly.Data.Array.Unboxed as A (reader, length, writeN)
9999import qualified Streamly.Data.Fold as FL
100100import qualified Streamly.Internal.Data.Array.Unboxed.Type as A
101101 (unsafeFreeze, asPtrUnsafe, byteLength, writeNUnsafe)
@@ -433,7 +433,7 @@ read = readWith defaultChunkSize
433433-- @since 0.9.0
434434{-# INLINE readerWith #-}
435435readerWith :: MonadIO m => Unfold m (Int, Socket) Word8
436−readerWith = UF.many A.read chunkReaderWith
436+readerWith = UF.many A.reader chunkReaderWith
437437
438438-- | Same as 'readWith'
439439--
src/Streamly/Internal/Unicode/Utf8.hs+3−2
@@ -27,7 +27,8 @@ import Data.Word (Word8)
2727import Streamly.Data.Array.Unboxed (Array)
2828import System.IO.Unsafe (unsafePerformIO)
2929
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)
3132import qualified Streamly.Internal.Data.Stream.IsStream as Stream
3233import qualified Streamly.Internal.Unicode.Stream as Unicode
3334
@@ -64,4 +65,4 @@ pack s =
6465unpack :: Utf8 -> String
6566unpack u =
6667 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"
2020#include "Streamly/Test/Data/Array/Common.hs"
2121
2222testFromStreamToStream :: Property
23−testFromStreamToStream = genericTestFromTo (const A.fromStream) A.toStream (==)
23+testFromStreamToStream =
24+ genericTestFromTo (const A.fromStream) A.read (==)
2425
2526testFoldUnfold :: Property
26−testFoldUnfold = genericTestFromTo (const (S.fold A.write)) (S.unfold A.read) (==)
27+testFoldUnfold =
28+ genericTestFromTo (const (S.fold A.write)) (S.unfold A.reader) (==)
2729
2830testFromList :: Property
2931testFromList =
@@ -31,7 +33,7 @@ testFromList =
3133 forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
3234 monadicIO $ do
3335 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
3537 assert (xs == list)
3638
3739testLengthFromStream :: Property
test/Streamly/Test/Data/Array/Common.hs+8−7
@@ -53,24 +53,25 @@ genericTestFromTo arrFold arrUnfold listEq =
5353
5454testFoldNUnfold :: Property
5555testFoldNUnfold =
56− genericTestFromTo (S.fold . A.writeN) (S.unfold A.read) (==)
56+ genericTestFromTo (S.fold . A.writeN) (S.unfold A.reader) (==)
5757
5858testFoldNToStream :: Property
5959testFoldNToStream =
60− genericTestFromTo (S.fold . A.writeN) A.toStream (==)
60+ genericTestFromTo (S.fold . A.writeN) A.read (==)
6161
6262testFoldNToStreamRev :: Property
6363testFoldNToStreamRev =
6464 genericTestFromTo
6565 (S.fold . A.writeN)
66− A.toStreamRev
66+ A.readRev
6767 (\xs list -> xs == reverse list)
6868
6969testFromStreamNUnfold :: Property
70−testFromStreamNUnfold = genericTestFromTo A.fromStreamN (S.unfold A.read) (==)
70+testFromStreamNUnfold =
71+ genericTestFromTo A.fromStreamN (S.unfold A.reader) (==)
7172
7273testFromStreamNToStream :: Property
73−testFromStreamNToStream = genericTestFromTo A.fromStreamN A.toStream (==)
74+testFromStreamNToStream = genericTestFromTo A.fromStreamN A.read (==)
7475
7576testFromListN :: Property
7677testFromListN =
@@ -79,7 +80,7 @@ testFromListN =
7980 forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
8081 monadicIO $ do
8182 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
8384 listEquals (==) xs (take n list)
8485
8586foldManyWith :: (Int -> Fold IO Int (Array Int)) -> Property
@@ -89,7 +90,7 @@ foldManyWith f =
8990 monadicIO $ do
9091 xs <- run
9192 $ S.fold Fold.toList
92− $ S.unfoldMany A.read
93+ $ S.unfoldMany A.reader
9394 $ S.foldMany (f 240)
9495 $ S.fromList list
9596 assert (xs == list)
test/Streamly/Test/Data/Array/Unboxed.hs+4−3
@@ -38,10 +38,11 @@ moduleName = "Data.Array.Unboxed"
3838#include "Streamly/Test/Data/Array/Common.hs"
3939
4040testFromStreamToStream :: Property
41−testFromStreamToStream = genericTestFromTo (const A.fromStream) A.toStream (==)
41+testFromStreamToStream = genericTestFromTo (const A.fromStream) A.read (==)
4242
4343testFoldUnfold :: Property
44−testFoldUnfold = genericTestFromTo (const (S.fold A.write)) (S.unfold A.read) (==)
44+testFoldUnfold =
45+ genericTestFromTo (const (S.fold A.write)) (S.unfold A.reader) (==)
4546
4647testFromList :: Property
4748testFromList =
@@ -49,7 +50,7 @@ testFromList =
4950 forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
5051 monadicIO $ do
5152 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
5354 assert (xs == list)
5455
5556testLengthFromStream :: Property
test/Streamly/Test/FileSystem/Event/Common.hs+1−1
@@ -104,7 +104,7 @@ eventMatches ev (expectedPath, f) =
104104
105105 utf8ToString :: Array Word8 -> String
106106 utf8ToString =
107− runIdentity . Stream.toList . Unicode.decodeUtf8' . Array.toStream
107+ runIdentity . Stream.toList . Unicode.decodeUtf8' . Array.read
108108
109109 evPath = utf8ToString (Event.getAbsPath ev)
110110
test/Streamly/Test/FileSystem/Handle.hs+3−3
@@ -56,7 +56,7 @@ toList = Stream.fold Fold.toList
5656
5757utf8ToString :: Array.Array Word8 -> String
5858utf8ToString =
59− runIdentity . toList . Unicode.decodeUtf8' . Array.toStream
59+ runIdentity . toList . Unicode.decodeUtf8' . Array.read
6060
6161testData :: String
6262testData = "This is the test data for FileSystem.Handle ??`!@#$%^&*~~))`]"
@@ -89,7 +89,7 @@ readWithBufferFromHandle =
8989readChunksFromHandle :: IO (Stream IO Char)
9090readChunksFromHandle =
9191 let f = Unicode.decodeUtf8
92− . Stream.concatMap Array.toStream
92+ . Stream.concatMap Array.read
9393 . Stream.unfold Handle.chunkReader
9494 in executor f
9595
@@ -98,7 +98,7 @@ readChunksWithBuffer =
9898 let f1 = (\h -> (1024, h))
9999 f2 =
100100 Unicode.decodeUtf8
101− . Stream.concatMap Array.toStream
101+ . Stream.concatMap Array.read
102102 . Stream.unfold Handle.chunkReaderWith
103103 . f1
104104 in executor f2