@@ -46,6 +46,7 @@ module Streamly.Internal.Data.Array
46 -- * Random Access
46 -- * Random Access
47 , getIndexUnsafe
47 , getIndexUnsafe
@@ -54,6 +55,7 @@ import Control.DeepSeq (NFData(..))
55import Control.Monad (when)
56import Control.Monad (when)
56import Control.Monad.IO.Class (liftIO, MonadIO)
57import Control.Monad.IO.Class (liftIO, MonadIO)
58+import Control.Monad.Primitive (PrimMonad)
57import Data.Functor.Identity (runIdentity)
59import Data.Functor.Identity (runIdentity)
58import Data.IORef
60import Data.IORef
59import GHC.Base (Int(..))
61import GHC.Base (Int(..))
@@ -313,3 +315,20 @@ strip p arr =
313 if p (indexArray arr idx) then getIndexR (idx - 1) else idx
315 if p (indexArray arr idx) then getIndexR (idx - 1) else idx
315 getIndexL idx = if p (indexArray arr idx) then getIndexL (idx + 1) else idx
317 getIndexL idx = if p (indexArray arr idx) then getIndexL (idx + 1) else idx
319+-- | Write an input stream of (index, value) pairs to an array. Throws an
320+-- error if any index is out of bounds.
323+{-# INLINE putIndices #-}
324+putIndices :: PrimMonad m
325+ => Array a -> Fold m (Int, a) ()
326+putIndices arr = FL.rmapM (\ _ -> return ()) (FL.foldlM' step initial)
330+ initial = unsafeThawArray arr
332+ step marr (i, x) = do