@@ -43,30 +43,23 @@ module Streamly.Internal.Memory.Array
4343
4444 -- , defaultChunkSize
4545
46− -- * Arrays
47− -- ** 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.
46+ -- * Construction
5447
5548 -- Pure List APIs
5649 , A.fromListN
5750 , A.fromList
5851
52+ -- Stream Folds
53+ , fromStreamN
54+ , fromStream
55+
5956 -- Monadic APIs
6057 -- , newArray
6158 , A.writeN -- drop new
6259 , A.write -- full buffer
6360 -- , writeLastN -- drop old (ring buffer)
6461
65− -- Stream Folds
66− -- , writeNS
67− -- , writeS
68−
69− -- ** Elimination
62+ -- * Elimination
7063 -- 'GHC.Exts.toList' from "GHC.Exts" can be used to convert an array to a
7164 -- list.
7265
@@ -74,30 +67,30 @@ module Streamly.Internal.Memory.Array
7467 , A.read
7568 , readRev
7669
77− -- ** Random Access
70+ -- * Random Access
7871 , length
72+ , null
7973 -- , (!!)
8074
8175 , readIndex
76+ , last
8277 {-
8378 , readSlice
8479 , readSliceRev
8580 -}
8681
87− -- , writeIndex
82+ , writeIndex
8883 {-
8984 , writeSlice
9085 , writeSliceRev
9186 -}
9287
93− {-
9488 -- * Immutable Transformations
95− , runTransform
89+ , streamTransform
9690
9791 -- * Folding Arrays
98− -- , runStreamFold
99− , runFold
100− -}
92+ , streamFold
93+ , fold
10194 )
10295where
10396
@@ -133,10 +126,10 @@ newArray len = undefined
133126-- allocated to size N, if the stream terminates before N elements then the
134127-- array may hold less than N elements.
135128--
136−-- @since 0.7.0
137−{-# INLINE _writeNS #-}
138−_writeNS :: (MonadIO m, Storable a) => Int -> SerialT m a -> m (Array a)
139−_writeNS n m = do
129+-- /Internal/
130+{-# INLINE fromStreamN #-}
131+fromStreamN :: (MonadIO m, Storable a) => Int -> SerialT m a -> m (Array a)
132+fromStreamN n m = do
140133 if n < 0 then error "writeN: negative write count specified" else return ()
141134 A.fromStreamDN n $ D.toStreamD m
142135
@@ -148,9 +141,10 @@ _writeNS n m = do
148141-- may fail. When the stream size is not known, `arraysOf` followed by
149142-- processing of indvidual arrays in the resulting stream should be preferred.
150143--
151−{-# INLINE _writeS #-}
152−_writeS :: (MonadIO m, Storable a) => SerialT m a -> m (Array a)
153−_writeS = P.runFold A.write
144+-- /Internal/
145+{-# INLINE fromStream #-}
146+fromStream :: (MonadIO m, Storable a) => SerialT m a -> m (Array a)
147+fromStream = P.runFold A.write
154148-- write m = A.fromStreamD $ D.toStreamD m
155149
156150-------------------------------------------------------------------------------
@@ -167,13 +161,19 @@ readRev = D.fromStreamD . A.toStreamDRev
167161-- {-# RULES "Streamly.Array.readRev fallback to StreamK" [1]
168162-- forall a. S.toStreamK (readRev a) = K.revFromArray a #-}
169163
170−{-# INLINE _null #-}
171−_null :: Storable a => Array a -> Bool
172−_null arr = length arr == 0
164+-- | > null arr = length arr == 0
165+--
166+-- /Internal/
167+{-# INLINE null #-}
168+null :: Storable a => Array a -> Bool
169+null arr = length arr == 0
173170
174−{-# INLINE _last #-}
175−_last :: Storable a => Array a -> Maybe a
176−_last arr = readIndex arr (length arr - 1)
171+-- | > last arr = readIndex arr (length arr - 1)
172+--
173+-- /Internal/
174+{-# INLINE last #-}
175+last :: Storable a => Array a -> Maybe a
176+last arr = readIndex arr (length arr - 1)
177177
178178-------------------------------------------------------------------------------
179179-- Random Access
@@ -311,10 +311,10 @@ readSliceRev arr i len = undefined
311311-- | /O(1)/ Write the given element at the given index in the array.
312312-- Performs in-place mutation of the array.
313313--
314−-- @since 0.7.0
315−{-# INLINE _writeIndex #-}
316−_writeIndex :: (MonadIO m, Storable a) => Array a -> Int -> a -> m ()
317−_writeIndex arr i a = do
314+-- /Internal/
315+{-# INLINE writeIndex #-}
316+writeIndex :: (MonadIO m, Storable a) => Array a -> Int -> a -> m ()
317+writeIndex arr i a = do
318318 let maxIndex = length arr - 1
319319 if i < 0
320320 then error "writeIndex: negative array index"
@@ -369,24 +369,24 @@ runPipe f arr = P.runPipe (toArrayMinChunk (length arr)) $ f (A.read arr)
369369-- | Transform an array into another array using a stream transformation
370370-- operation.
371371--
372−-- @since 0.7.0
373−{-# INLINE _runTransform #-}
374−_runTransform :: forall m a b. (MonadIO m, Storable a, Storable b)
372+-- /Internal/
373+{-# INLINE streamTransform #-}
374+streamTransform :: forall m a b. (MonadIO m, Storable a, Storable b)
375375 => (SerialT m a -> SerialT m b) -> Array a -> m (Array b)
376−_runTransform f arr =
376+streamTransform f arr =
377377 P.runFold (A.toArrayMinChunk (alignment (undefined :: a)) (length arr))
378378 $ f (A.read arr)
379379
380380-- | Fold an array using a 'Fold'.
381381--
382−-- @since 0.7.0
383−{-# INLINE _runFold #-}
384−_runFold :: 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)
382+-- /Internal/
383+{-# INLINE fold #-}
384+fold :: forall m a b. (MonadIO m, Storable a) => Fold m a b -> Array a -> m b
385+fold f arr = P.runFold f $ (A.read arr :: Serial.SerialT m a)
386386
387387-- | Fold an array using a stream fold operation.
388388--
389−-- @since 0.7.0
390−{-# INLINE _runStreamFold #-}
391−_runStreamFold :: (MonadIO m, Storable a) => (SerialT m a -> m b) -> Array a -> m b
392−_runStreamFold f arr = f (A.read arr)
389+-- /Internal/
390+{-# INLINE streamFold #-}
391+streamFold :: (MonadIO m, Storable a) => (SerialT m a -> m b) -> Array a -> m b
392+streamFold f arr = f (A.read arr)