@@ -78,6 +78,7 @@ module Data.Vector.Generic.Mutable (
78
78
PrimMonad , PrimState , RealWorld
79
79
) where
80
80
81
+ import Control.Monad ((<=<) )
81
82
import Data.Vector.Generic.Mutable.Base
82
83
import qualified Data.Vector.Generic.Base as V
83
84
@@ -1221,34 +1222,31 @@ partitionWithUnknown f s
1221
1222
-- @since NEXT_VERSION
1222
1223
mapInPlace :: (PrimMonad m , MVector v a ) => (a -> a ) -> v (PrimState m ) a -> m ()
1223
1224
{-# INLINE mapInPlace #-}
1224
- mapInPlace f v
1225
- = stToPrim
1226
- $ forI_ v $ \ i -> unsafeWrite v i . f =<< unsafeRead v i
1225
+ mapInPlace f = imapInPlace (\ _ -> f)
1227
1226
1228
1227
-- | Modify vector in place by applying function to each element and its index.
1229
1228
--
1230
1229
-- @since NEXT_VERSION
1231
1230
imapInPlace :: (PrimMonad m , MVector v a ) => (Int -> a -> a ) -> v (PrimState m ) a -> m ()
1232
1231
{-# INLINE imapInPlace #-}
1233
1232
imapInPlace f v
1234
- = stToPrim
1235
- $ forI_ v $ \ i -> unsafeWrite v i . f i =<< unsafeRead v i
1233
+ = stToPrim $ iforM_ v $ \ i -> unsafeWrite v i . f i
1236
1234
1237
1235
-- | Modify vector in place by applying monadic function to each element in order.
1238
1236
--
1239
1237
-- @since NEXT_VERSION
1240
1238
mapInPlaceM :: (PrimMonad m , MVector v a ) => (a -> m a ) -> v (PrimState m ) a -> m ()
1241
1239
{-# INLINE mapInPlaceM #-}
1242
- mapInPlaceM f v
1243
- = forI_ v $ \ i -> unsafeWrite v i =<< f =<< unsafeRead v i
1240
+ mapInPlaceM f
1241
+ = imapInPlaceM ( \ _ -> f)
1244
1242
1245
1243
-- | Modify vector in place by applying monadic function to each element and its index in order.
1246
1244
--
1247
1245
-- @since NEXT_VERSION
1248
1246
imapInPlaceM :: (PrimMonad m , MVector v a ) => (Int -> a -> m a ) -> v (PrimState m ) a -> m ()
1249
1247
{-# INLINE imapInPlaceM #-}
1250
1248
imapInPlaceM f v
1251
- = forI_ v $ \ i -> unsafeWrite v i =<< f i =<< unsafeRead v i
1249
+ = iforM_ v $ \ i -> unsafeWrite v i <=< f i
1252
1250
1253
1251
1254
1252
-- | Compute the (lexicographically) next permutation of the given vector in-place.
0 commit comments