on master help sign in
Implement Array modifyIndices may accept index as argument
e01bc90Ranjeet Kumar Ranjan
benchmark/Streamly/Benchmark/Data/Array/Foreign/Mut.hs+1−1
@@ -66,7 +66,7 @@ o_1_space_serial_marray value ~(array, indices) =
66 , benchIO "strip (> 0)" (const array)
66 , benchIO "strip (> 0)" (const array)
67 $ MArray.strip (> 0)
67 $ MArray.strip (> 0)
68 , benchIO "modifyIndices (+ 1)" (const indices)
68 , benchIO "modifyIndices (+ 1)" (const indices)
69− $ Stream.fold (MArray.modifyIndices (+ 1) array)
69+ $ Stream.fold (MArray.modifyIndices (\_idx val -> val + 1) array)
70 . Stream.unfold Array.read
70 . Stream.unfold Array.read
71 ]
71 ]
72
72
core/src/Streamly/Internal/Data/Array/Foreign/Mut/Type.hs+3−3
@@ -624,8 +624,8 @@ modifyIndex i f arr@(Array{..}) = do
624--
624--
625-- /Pre-release/
625-- /Pre-release/
626{-# INLINE modifyIndices #-}
626{-# INLINE modifyIndices #-}
627−modifyIndices :: forall m a. (MonadIO m, Storable a)
627+modifyIndices :: forall m a . (MonadIO m, Storable a)
628− => (a -> a) -> Array a -> Fold m Int ()
628+ => (Int -> a -> a) -> Array a -> Fold m Int ()
629modifyIndices f Array{..} = Fold step initial extract
629modifyIndices f Array{..} = Fold step initial extract
630
630
631 where
631 where
@@ -633,7 +633,7 @@ modifyIndices f Array{..} = Fold step initial extract
633 initial = return $ FL.Partial ()
633 initial = return $ FL.Partial ()
634
634
635 step () i =
635 step () i =
636− let f1 x = (f x, ())
636+ let f1 x = (f i x, ())
637 in FL.Partial <$> liftIO (modifyIndexPtr i f1 arrStart aEnd)
637 in FL.Partial <$> liftIO (modifyIndexPtr i f1 arrStart aEnd)
638
638
639 extract () = liftIO $ touch arrContents
639 extract () = liftIO $ touch arrContents