@@ -547,14 +547,6 @@ withNewArrayUnsafe count f = do
547-- Random writes
547-- Random writes
548-------------------------------------------------------------------------------
548-------------------------------------------------------------------------------
550−-- | Write an input stream of (index, value) pairs to an array. Throws an
551−-- error if any index is out of bounds.
554−{-# INLINE putIndices #-}
555−putIndices :: Array a -> Fold m (Int, a) ()
556−putIndices = undefined
558-- | Write the given element to the given index of the array. Does not check if
550-- | Write the given element to the given index of the array. Does not check if
559-- the index is out of bounds of the array.
551-- the index is out of bounds of the array.
@@ -597,6 +589,23 @@ putIndex arr i x =
597 unsafeWithArrayContents (arrContents arr) (arrStart arr)
589 unsafeWithArrayContents (arrContents arr) (arrStart arr)
598 $ \p -> putIndexPtr p (aEnd arr) i x
590 $ \p -> putIndexPtr p (aEnd arr) i x
592+-- | Write an input stream of (index, value) pairs to an array. Throws an
593+-- error if any index is out of bounds.
596+{-# INLINE putIndices #-}
597+putIndices :: forall m a. (MonadIO m, Storable a)
598+ => Array a -> Fold m (Int, a) ()
599+putIndices Array{..} = FL.mkFoldM step initial extract
603+ initial = return $ FL.Partial ()
605+ step () (i, x) = FL.Partial <$> liftIO (putIndexPtr arrStart aEnd i x)
607+ extract () = liftIO $ touch arrContents
600-- | Modify a given index of an array using a modifier function.
609-- | Modify a given index of an array using a modifier function.
602-- /Pre-release/
611-- /Pre-release/