on master help sign in
Implement modify
77998d1Ranjeet Kumar Ranjan
src/Streamly/Internal/Data/Array/Foreign/Mut/Type.hs+14−4
@@ -635,10 +635,20 @@ modifyIndices = undefined
635
635
636-- | Modify each element of an array using the supplied modifier function.
636-- | Modify each element of an array using the supplied modifier function.
637--
637--
638−-- /Unimplemented/
638+-- /Pre-release/
639−modify :: -- forall m a b. (MonadIO m, Storable a) =>
639+modify :: forall m a. (MonadIO m, Storable a)
640− Array a -> (a -> a) -> m ()
640+ => Array a -> (a -> a) -> m ()
641+modify Array{..} f = liftIO $
642+ unsafeWithArrayContents arrContents arrStart go
643+
644+ where
645+
646+ go ptr = do
641−modify = undefined
647+ let elemSize = sizeOf (undefined :: a)
648+ when (ptr `plusPtr` elemSize <= aEnd) $ do
649+ r <- peek ptr
650+ poke ptr (f r)
651+ go (ptr `plusPtr` elemSize)
642
652
643-- | Swap the elements at two indices.
653-- | Swap the elements at two indices.
644--
654--