@@ -45,15 +45,13 @@ module Streamly.Internal.Data.Array.Type
4545
4646 -- *** Stream Folds
4747 , unsafeMakePure
48− , writeWith
49− , writeN
50− , pinnedWriteN
51− , writeNUnsafe
52− , pinnedWriteNUnsafe
53− -- , MA.ArrayUnsafe (..)
54− , pinnedWriteNAligned
55− , write
56− , pinnedWrite
48+ , createOf
49+ , pinnedCreateOf
50+ , unsafeCreateOf
51+ , unsafePinnedCreateOf
52+ , create
53+ , pinnedCreate
54+ , createWith
5755
5856 -- *** From containers
5957 , fromListN
@@ -75,8 +73,8 @@ module Streamly.Internal.Data.Array.Type
7573 -- ** Reading
7674
7775 -- *** Indexing
78− , unsafeIndexIO -- XXX rename to getIndexUnsafeIO
79− , getIndexUnsafe
76+ , unsafeIndexIO -- XXX unsafeGetIndexIO
77+ , getIndexUnsafe -- XXX unsafeGetIndex
8078
8179 -- *** To Streams
8280 , read
@@ -143,6 +141,14 @@ module Streamly.Internal.Data.Array.Type
143141 , toStream
144142 , toStreamRev
145143 , nil
144+ , writeWith
145+ , writeN
146+ , pinnedWriteN
147+ , writeNUnsafe
148+ , pinnedWriteNUnsafe
149+ , pinnedWriteNAligned
150+ , write
151+ , pinnedWrite
146152 )
147153where
148154
@@ -745,17 +751,28 @@ toList s = build (\c n -> toListFB c n s)
745751-- Folds
746752-------------------------------------------------------------------------------
747753
748−-- | @writeN n@ folds a maximum of @n@ elements from the input stream to an
754+-- | @createOf n@ folds a maximum of @n@ elements from the input stream to an
749755-- 'Array'.
750756--
751−{-# INLINE_NORMAL writeN #-}
757+{-# INLINE_NORMAL createOf #-}
758+createOf :: forall m a. (MonadIO m, Unbox a) => Int -> Fold m a (Array a)
759+createOf = fmap unsafeFreeze . MA.createOf
760+
761+-- XXX Deprecate in major
762+-- {-# DEPRECATED writeN "Please use createOf instead." #-}
763+{-# INLINE writeN #-}
752764writeN :: forall m a. (MonadIO m, Unbox a) => Int -> Fold m a (Array a)
753−writeN = fmap unsafeFreeze . MA.writeN
765+writeN = createOf
754766
755−-- | Like 'fromListN' but creates a pinned array.
756−{-# INLINE_NORMAL pinnedWriteN #-}
767+-- | Like 'createOf' but creates a pinned array.
768+{-# INLINE_NORMAL pinnedCreateOf #-}
769+pinnedCreateOf :: forall m a. (MonadIO m, Unbox a) => Int -> Fold m a (Array a)
770+pinnedCreateOf = fmap unsafeFreeze . MA.pinnedCreateOf
771+
772+{-# DEPRECATED pinnedWriteN "Please use pinnedCreateOf instead." #-}
773+{-# INLINE pinnedWriteN #-}
757774pinnedWriteN :: forall m a. (MonadIO m, Unbox a) => Int -> Fold m a (Array a)
758−pinnedWriteN = fmap unsafeFreeze . MA.pinnedCreateOf
775+pinnedWriteN = pinnedCreateOf
759776
760777-- | @pinnedWriteNAligned alignment n@ folds a maximum of @n@ elements from the input
761778-- stream to an 'Array' aligned to the given size.
@@ -763,44 +780,74 @@ pinnedWriteN = fmap unsafeFreeze . MA.pinnedCreateOf
763780-- /Pre-release/
764781--
765782{-# INLINE_NORMAL pinnedWriteNAligned #-}
783+{-# DEPRECATED pinnedWriteNAligned "To be removed." #-}
766784pinnedWriteNAligned :: forall m a. (MonadIO m, Unbox a)
767785 => Int -> Int -> Fold m a (Array a)
768786pinnedWriteNAligned alignSize = fmap unsafeFreeze . MA.pinnedWriteNAligned alignSize
769787
770−-- | Like 'writeN' but does not check the array bounds when writing. The fold
788+-- | Like 'createOf' but does not check the array bounds when writing. The fold
771789-- driver must not call the step function more than 'n' times otherwise it will
772790-- corrupt the memory and crash. This function exists mainly because any
773791-- conditional in the step function blocks fusion causing 10x performance
774792-- slowdown.
775793--
776−{-# INLINE_NORMAL writeNUnsafe #-}
794+{-# INLINE_NORMAL unsafeCreateOf #-}
795+unsafeCreateOf :: forall m a. (MonadIO m, Unbox a)
796+ => Int -> Fold m a (Array a)
797+unsafeCreateOf n = unsafeFreeze <$> MA.unsafeCreateOf n
798+
799+{-# DEPRECATED writeNUnsafe "Please use unsafeCreateOf instead." #-}
800+{-# INLINE writeNUnsafe #-}
777801writeNUnsafe :: forall m a. (MonadIO m, Unbox a)
778802 => Int -> Fold m a (Array a)
779−writeNUnsafe n = unsafeFreeze <$> MA.unsafeCreateOf n
803+writeNUnsafe = unsafeCreateOf
780804
781−{-# INLINE_NORMAL pinnedWriteNUnsafe #-}
805+{-# INLINE_NORMAL unsafePinnedCreateOf #-}
806+unsafePinnedCreateOf :: forall m a. (MonadIO m, Unbox a)
807+ => Int -> Fold m a (Array a)
808+unsafePinnedCreateOf n = unsafeFreeze <$> MA.unsafePinnedCreateOf n
809+
810+{-# DEPRECATED pinnedWriteNUnsafe "Please use unsafePinnedCreateOf instead." #-}
811+{-# INLINE pinnedWriteNUnsafe #-}
782812pinnedWriteNUnsafe :: forall m a. (MonadIO m, Unbox a)
783813 => Int -> Fold m a (Array a)
784−pinnedWriteNUnsafe n = unsafeFreeze <$> MA.unsafePinnedCreateOf n
814+pinnedWriteNUnsafe = unsafePinnedCreateOf
815+
816+{-# INLINE_NORMAL createWith #-}
817+createWith :: forall m a. (MonadIO m, Unbox a)
818+ => Int -> Fold m a (Array a)
819+-- createWith n = FL.rmapM spliceArrays $ toArraysOf n
820+createWith elemCount = unsafeFreeze <$> MA.createWith elemCount
785821
786−{-# INLINE_NORMAL writeWith #-}
822+{-# DEPRECATED writeWith "Please use createWith instead." #-}
823+{-# INLINE writeWith #-}
787824writeWith :: forall m a. (MonadIO m, Unbox a)
788825 => Int -> Fold m a (Array a)
789−-- writeWith n = FL.rmapM spliceArrays $ toArraysOf n
790−writeWith elemCount = unsafeFreeze <$> MA.createWith elemCount
826+writeWith = createWith
791827
792828-- | Fold the whole input to a single array.
793829--
794830-- /Caution! Do not use this on infinite streams./
795831--
832+{-# INLINE create #-}
833+create :: forall m a. (MonadIO m, Unbox a) => Fold m a (Array a)
834+create = fmap unsafeFreeze MA.create
835+
836+-- XXX Deprecate in major
837+-- {-# DEPRECATED write "Please use create instead." #-}
796838{-# INLINE write #-}
797839write :: forall m a. (MonadIO m, Unbox a) => Fold m a (Array a)
798−write = fmap unsafeFreeze MA.write
840+write = create
841+
842+-- | Like 'create' but creates a pinned array.
843+{-# INLINE pinnedCreate #-}
844+pinnedCreate :: forall m a. (MonadIO m, Unbox a) => Fold m a (Array a)
845+pinnedCreate = fmap unsafeFreeze MA.pinnedCreate
799846
800−-- | Like 'write' but creates a pinned array.
847+{-# DEPRECATED pinnedWrite "Please use pinnedCreate instead." #-}
801848{-# INLINE pinnedWrite #-}
802849pinnedWrite :: forall m a. (MonadIO m, Unbox a) => Fold m a (Array a)
803−pinnedWrite = fmap unsafeFreeze MA.pinnedCreate
850+pinnedWrite = pinnedCreate
804851
805852-- | Fold "step" has a dependency on "initial", and each step is dependent on
806853-- the previous invocation of step due to state passing, finally extract