on master help sign in
Deprecate fromStreamD and fromStreamDN in Array
6a56740Harendra Kumar
core/src/Streamly/Internal/Data/Array.hs−34
@@ -20,10 +20,6 @@ module Streamly.Internal.Data.Array
20 module Streamly.Internal.Data.Array.Type
20 module Streamly.Internal.Data.Array.Type
21
21
22 -- * Construction
22 -- * Construction
23− -- Stream Folds
24− , fromStreamN
25− , fromStream
26−
27 -- Monadic Folds
23 -- Monadic Folds
28 , writeLastN
24 , writeLastN
29
25
@@ -86,7 +82,6 @@ where
86#include "inline.hs"
82#include "inline.hs"
87#include "ArrayMacros.h"
83#include "ArrayMacros.h"
88
84
89−import Control.Monad (when)
90import Control.Monad.IO.Class (MonadIO(..))
85import Control.Monad.IO.Class (MonadIO(..))
91import Data.Functor.Identity (Identity)
86import Data.Functor.Identity (Identity)
92import Data.Proxy (Proxy(..))
87import Data.Proxy (Proxy(..))
@@ -145,35 +140,6 @@ import Streamly.Internal.Data.Array.Type
145-- if we use one array for each chunk. This is still significant to add
140-- if we use one array for each chunk. This is still significant to add
146-- pressure to GC.
141-- pressure to GC.
147
142
148−-------------------------------------------------------------------------------
149−-- Construction
150−-------------------------------------------------------------------------------
151−
152−-- | Create an 'Array' from the first N elements of a stream. The array is
153−-- allocated to size N, if the stream terminates before N elements then the
154−-- array may hold less than N elements.
155−--
156−-- /Pre-release/
157−{-# INLINE fromStreamN #-}
158−fromStreamN :: (MonadIO m, Unbox a) => Int -> Stream m a -> m (Array a)
159−fromStreamN n m = do
160− when (n < 0) $ error "writeN: negative write count specified"
161− A.fromStreamDN n m
162−
163−-- | Create an 'Array' from a stream. This is useful when we want to create a
164−-- single array from a stream of unknown size. 'writeN' is at least twice
165−-- as efficient when the size is already known.
166−--
167−-- Note that if the input stream is too large memory allocation for the array
168−-- may fail. When the stream size is not known, `chunksOf` followed by
169−-- processing of indvidual arrays in the resulting stream should be preferred.
170−--
171−-- /Pre-release/
172−{-# INLINE fromStream #-}
173−fromStream :: (MonadIO m, Unbox a) => Stream m a -> m (Array a)
174−fromStream = Stream.fold A.write
175−-- write m = A.fromStreamD $ D.fromStreamK m
176−
177-------------------------------------------------------------------------------
143-------------------------------------------------------------------------------
178-- Elimination
144-- Elimination
179-------------------------------------------------------------------------------
145-------------------------------------------------------------------------------
core/src/Streamly/Internal/Data/Array/Type.hs+38−6
@@ -37,8 +37,8 @@ module Streamly.Internal.Data.Array.Type
37 , pinnedFromListN
37 , pinnedFromListN
38 , fromListRev
38 , fromListRev
39 , fromListRevN
39 , fromListRevN
40− , fromStreamDN
40+ , fromStreamN
41− , fromStreamD
41+ , fromStream
42 , fromPureStreamN
42 , fromPureStreamN
43 , fromPureStream
43 , fromPureStream
44 , fromByteStr#
44 , fromByteStr#
@@ -101,6 +101,8 @@ module Streamly.Internal.Data.Array.Type
101 , flattenArrays
101 , flattenArrays
102 , flattenArraysRev
102 , flattenArraysRev
103 , fromArrayStreamK
103 , fromArrayStreamK
104+ , fromStreamDN
105+ , fromStreamD
104 )
106 )
105where
107where
106
108
@@ -108,7 +110,7 @@ where
108#include "inline.hs"
110#include "inline.hs"
109
111
110import Control.Exception (assert)
112import Control.Exception (assert)
111−import Control.Monad (replicateM)
113+import Control.Monad (replicateM, when)
112import Control.Monad.IO.Class (MonadIO(..))
114import Control.Monad.IO.Class (MonadIO(..))
113import Data.Functor.Identity (Identity(..))
115import Data.Functor.Identity (Identity(..))
114import Data.Int (Int8, Int16, Int32, Int64)
116import Data.Int (Int8, Int16, Int32, Int64)
@@ -314,15 +316,45 @@ pinnedFromList xs = unsafePerformIO $ unsafeFreeze <$> MA.pinnedFromList xs
314fromListRev :: Unbox a => [a] -> Array a
316fromListRev :: Unbox a => [a] -> Array a
315fromListRev xs = unsafePerformIO $ unsafeFreeze <$> MA.fromListRev xs
317fromListRev xs = unsafePerformIO $ unsafeFreeze <$> MA.fromListRev xs
316
318
319+-- | Create an 'Array' from the first N elements of a stream. The array is
320+-- allocated to size N, if the stream terminates before N elements then the
321+-- array may hold less than N elements.
322+--
323+-- >>> fromStreamN n = Stream.fold (Array.writeN n)
324+--
325+-- /Pre-release/
317−{-# INLINE_NORMAL fromStreamDN #-}
326+{-# INLINE_NORMAL fromStreamN #-}
327+fromStreamN :: (MonadIO m, Unbox a) => Int -> Stream m a -> m (Array a)
328+fromStreamN n m = do
329+ when (n < 0) $ error "writeN: negative write count specified"
330+ unsafeFreeze <$> MA.fromStreamN n m
331+-- fromStreamN n = D.fold (writeN n)
332+
333+{-# DEPRECATED fromStreamDN "Please use fromStreamN instead." #-}
318fromStreamDN :: forall m a. (MonadIO m, Unbox a)
334fromStreamDN :: forall m a. (MonadIO m, Unbox a)
319 => Int -> D.Stream m a -> m (Array a)
335 => Int -> D.Stream m a -> m (Array a)
320−fromStreamDN limit str = unsafeFreeze <$> MA.fromStreamDN limit str
336+fromStreamDN = fromStreamN
321
337
338+-- | Create an 'Array' from a stream. This is useful when we want to create a
339+-- single array from a stream of unknown size. 'writeN' is at least twice
340+-- as efficient when the size is already known.
341+--
342+-- >>> fromStream = Stream.fold Array.write
343+--
344+-- Note that if the input stream is too large memory allocation for the array
345+-- may fail. When the stream size is not known, `chunksOf` followed by
346+-- processing of indvidual arrays in the resulting stream should be preferred.
347+--
348+-- /Pre-release/
322{-# INLINE_NORMAL fromStreamD #-}
349{-# INLINE_NORMAL fromStreamD #-}
350+fromStream :: (MonadIO m, Unbox a) => Stream m a -> m (Array a)
351+fromStream = D.fold write
352+-- fromStreamD str = unsafeFreeze <$> MA.fromStream str
353+
354+{-# DEPRECATED fromStreamD "Please use fromStream instead." #-}
323fromStreamD :: forall m a. (MonadIO m, Unbox a)
355fromStreamD :: forall m a. (MonadIO m, Unbox a)
324 => D.Stream m a -> m (Array a)
356 => D.Stream m a -> m (Array a)
325−fromStreamD str = unsafeFreeze <$> MA.fromStreamD str
357+fromStreamD = fromStream
326
358
327-------------------------------------------------------------------------------
359-------------------------------------------------------------------------------
328-- Cloning
360-- Cloning