@@ -43,30 +43,23 @@ module Streamly.Internal.Memory.Array
44 -- , defaultChunkSize
44 -- , defaultChunkSize
47− -- ** Construction
46+ -- * Construction
48− -- | When performance matters, the fastest way to generate an array is
49− -- 'writeN'. For regular use, 'IsList' and 'IsString' instances can be
50− -- used to conveniently construct arrays from literal values.
51− -- 'OverloadedLists' extension or 'fromList' can be used to construct an
52− -- array from a list literal. Similarly, 'OverloadedStrings' extension or
53− -- 'fromList' can be used to construct an array from a string literal.
55 -- Pure List APIs
48 -- Pure List APIs
56 , A.fromListN
49 , A.fromListN
57 , A.fromList
50 , A.fromList
59 -- Monadic APIs
56 -- Monadic APIs
60 -- , newArray
57 -- , newArray
61 , A.writeN -- drop new
58 , A.writeN -- drop new
62 , A.write -- full buffer
59 , A.write -- full buffer
63 -- , writeLastN -- drop old (ring buffer)
60 -- , writeLastN -- drop old (ring buffer)
69− -- ** Elimination
62+ -- * Elimination
70 -- 'GHC.Exts.toList' from "GHC.Exts" can be used to convert an array to a
63 -- 'GHC.Exts.toList' from "GHC.Exts" can be used to convert an array to a
@@ -74,30 +67,30 @@ module Streamly.Internal.Memory.Array
77− -- ** Random Access
70+ -- * Random Access
81 , readIndex
75 , readIndex
83 , readSlice
78 , readSlice
84 , readSliceRev
79 , readSliceRev
87− -- , writeIndex
82+ , writeIndex
89 , writeSlice
84 , writeSlice
90 , writeSliceRev
85 , writeSliceRev
94 -- * Immutable Transformations
88 -- * Immutable Transformations
95− , runTransform
89+ , streamTransform
97 -- * Folding Arrays
91 -- * Folding Arrays
98− -- , runStreamFold
92+ , streamFold
@@ -133,10 +126,10 @@ newArray len = undefined
133-- allocated to size N, if the stream terminates before N elements then the
126-- allocated to size N, if the stream terminates before N elements then the
134-- array may hold less than N elements.
127-- array may hold less than N elements.
136−-- @since 0.7.0
129+-- /Internal/
137−{-# INLINE _writeNS #-}
130+{-# INLINE fromStreamN #-}
138−_writeNS :: (MonadIO m, Storable a) => Int -> SerialT m a -> m (Array a)
131+fromStreamN :: (MonadIO m, Storable a) => Int -> SerialT m a -> m (Array a)
139−_writeNS n m = do
132+fromStreamN n m = do
140 if n < 0 then error "writeN: negative write count specified" else return ()
133 if n < 0 then error "writeN: negative write count specified" else return ()
141 A.fromStreamDN n $ D.toStreamD m
134 A.fromStreamDN n $ D.toStreamD m
@@ -148,9 +141,10 @@ _writeNS n m = do
148-- may fail. When the stream size is not known, `arraysOf` followed by
141-- may fail. When the stream size is not known, `arraysOf` followed by
149-- processing of indvidual arrays in the resulting stream should be preferred.
142-- processing of indvidual arrays in the resulting stream should be preferred.
151−{-# INLINE _writeS #-}
145+{-# INLINE fromStream #-}
152−_writeS :: (MonadIO m, Storable a) => SerialT m a -> m (Array a)
146+fromStream :: (MonadIO m, Storable a) => SerialT m a -> m (Array a)
153−_writeS = P.runFold A.write
147+fromStream = P.runFold A.write
154-- write m = A.fromStreamD $ D.toStreamD m
148-- write m = A.fromStreamD $ D.toStreamD m
156-------------------------------------------------------------------------------
150-------------------------------------------------------------------------------
@@ -167,13 +161,19 @@ readRev = D.fromStreamD . A.toStreamDRev
167-- {-# RULES "Streamly.Array.readRev fallback to StreamK" [1]
161-- {-# RULES "Streamly.Array.readRev fallback to StreamK" [1]
168-- forall a. S.toStreamK (readRev a) = K.revFromArray a #-}
162-- forall a. S.toStreamK (readRev a) = K.revFromArray a #-}
164+-- | > null arr = length arr == 0
170−{-# INLINE _null #-}
167+{-# INLINE null #-}
171−_null :: Storable a => Array a -> Bool
168+null :: Storable a => Array a -> Bool
172−_null arr = length arr == 0
169+null arr = length arr == 0
171+-- | > last arr = readIndex arr (length arr - 1)
174−{-# INLINE _last #-}
174+{-# INLINE last #-}
175−_last :: Storable a => Array a -> Maybe a
175+last :: Storable a => Array a -> Maybe a
176−_last arr = readIndex arr (length arr - 1)
176+last arr = readIndex arr (length arr - 1)
178-------------------------------------------------------------------------------
178-------------------------------------------------------------------------------
179-- Random Access
179-- Random Access
@@ -311,10 +311,10 @@ readSliceRev arr i len = undefined
311-- | /O(1)/ Write the given element at the given index in the array.
311-- | /O(1)/ Write the given element at the given index in the array.
312-- Performs in-place mutation of the array.
312-- Performs in-place mutation of the array.
314−-- @since 0.7.0
314+-- /Internal/
315−{-# INLINE _writeIndex #-}
315+{-# INLINE writeIndex #-}
316−_writeIndex :: (MonadIO m, Storable a) => Array a -> Int -> a -> m ()
316+writeIndex :: (MonadIO m, Storable a) => Array a -> Int -> a -> m ()
317−_writeIndex arr i a = do
317+writeIndex arr i a = do
318 let maxIndex = length arr - 1
318 let maxIndex = length arr - 1
320 then error "writeIndex: negative array index"
320 then error "writeIndex: negative array index"
@@ -369,24 +369,24 @@ runPipe f arr = P.runPipe (toArrayMinChunk (length arr)) $ f (A.read arr)
369-- | Transform an array into another array using a stream transformation
369-- | Transform an array into another array using a stream transformation
370-- operation.
370-- operation.
372−-- @since 0.7.0
372+-- /Internal/
373−{-# INLINE _runTransform #-}
373+{-# INLINE streamTransform #-}
374−_runTransform :: forall m a b. (MonadIO m, Storable a, Storable b)
374+streamTransform :: forall m a b. (MonadIO m, Storable a, Storable b)
375 => (SerialT m a -> SerialT m b) -> Array a -> m (Array b)
375 => (SerialT m a -> SerialT m b) -> Array a -> m (Array b)
376−_runTransform f arr =
376+streamTransform f arr =
377 P.runFold (A.toArrayMinChunk (alignment (undefined :: a)) (length arr))
377 P.runFold (A.toArrayMinChunk (alignment (undefined :: a)) (length arr))
378 $ f (A.read arr)
378 $ f (A.read arr)
380-- | Fold an array using a 'Fold'.
380-- | Fold an array using a 'Fold'.
382−-- @since 0.7.0
382+-- /Internal/
383−{-# INLINE _runFold #-}
383+{-# INLINE fold #-}
384−_runFold :: forall m a b. (MonadIO m, Storable a) => Fold m a b -> Array a -> m b
384+fold :: forall m a b. (MonadIO m, Storable a) => Fold m a b -> Array a -> m b
385−_runFold f arr = P.runFold f $ (A.read arr :: Serial.SerialT m a)
385+fold f arr = P.runFold f $ (A.read arr :: Serial.SerialT m a)
387-- | Fold an array using a stream fold operation.
387-- | Fold an array using a stream fold operation.
389−-- @since 0.7.0
389+-- /Internal/
390−{-# INLINE _runStreamFold #-}
390+{-# INLINE streamFold #-}
391−_runStreamFold :: (MonadIO m, Storable a) => (SerialT m a -> m b) -> Array a -> m b
391+streamFold :: (MonadIO m, Storable a) => (SerialT m a -> m b) -> Array a -> m b
392−_runStreamFold f arr = f (A.read arr)
392+streamFold f arr = f (A.read arr)