@@ -41,7 +41,7 @@ module Streamly.Internal.Data.Array.Generic.Mut.Type
4141 -- * Random writes
4242 , putIndex
4343 , putIndexUnsafe
44− -- , putIndices
44+ , putIndices
4545 -- , putFromThenTo
4646 -- , putFrom -- start writing at the given position
4747 -- , putUpto -- write from beginning up to the given position
@@ -283,6 +283,19 @@ putIndex i arr@MutArray {..} x =
283283 then putIndexUnsafe i arr x
284284 else invalidIndex "putIndex" i
285285
286+-- | Write an input stream of (index, value) pairs to an array. Throws an
287+-- error if any index is out of bounds.
288+--
289+-- /Pre-release/
290+{-# INLINE putIndices #-}
291+putIndices :: MonadIO m
292+ => MutArray a -> Fold m (Int, a) ()
293+putIndices arr = FL.foldlM' step (return ())
294+
295+ where
296+
297+ step () (i, x) = liftIO (putIndex i arr x)
298+
286299-- | Modify a given index of an array using a modifier function without checking
287300-- the bounds.
288301--
@@ -367,8 +380,9 @@ reallocWith label sizer reqSize arr = do
367380snocUnsafe :: MonadIO m => MutArray a -> a -> m (MutArray a)
368381snocUnsafe arr@MutArray {..} a = do
369382 assert (arrStart + arrLen < arrTrueLen) (return ())
370− putIndexUnsafe arrLen arr a
371− return $ arr {arrLen = arrLen + 1}
383+ let arr1 = arr {arrLen = arrLen + 1}
384+ putIndexUnsafe arrLen arr1 a
385+ return arr1
372386
373387-- NOINLINE to move it out of the way and not pollute the instruction cache.
374388{-# NOINLINE snocWithRealloc #-}