Skip to content

Commit 3bc592f

Browse files
committed
concrete modify
1 parent 29e364e commit 3bc592f

File tree

4 files changed

+48
-8
lines changed

4 files changed

+48
-8
lines changed

Data/Vector/Mutable.hs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ module Data.Vector.Mutable (
4040
clear,
4141

4242
-- * Accessing individual elements
43-
read, write, swap,
44-
unsafeRead, unsafeWrite, unsafeSwap,
43+
read, write, modify, swap,
44+
unsafeRead, unsafeWrite, unsafeModify, unsafeSwap,
4545

4646
-- * Modifying vectors
4747

@@ -325,6 +325,11 @@ write :: PrimMonad m => MVector (PrimState m) a -> Int -> a -> m ()
325325
{-# INLINE write #-}
326326
write = G.write
327327

328+
-- | Modify the element at the given position.
329+
modify :: PrimMonad m => MVector (PrimState m) a -> (a -> a) -> Int -> m ()
330+
{-# INLINE modify #-}
331+
modify = G.modify
332+
328333
-- | Swap the elements at the given positions.
329334
swap :: PrimMonad m => MVector (PrimState m) a -> Int -> Int -> m ()
330335
{-# INLINE swap #-}
@@ -341,6 +346,11 @@ unsafeWrite :: PrimMonad m => MVector (PrimState m) a -> Int -> a -> m ()
341346
{-# INLINE unsafeWrite #-}
342347
unsafeWrite = G.unsafeWrite
343348

349+
-- | Modify the element at the given position. No bounds checks are performed.
350+
unsafeModify :: PrimMonad m => MVector (PrimState m) a -> (a -> a) -> Int -> m ()
351+
{-# INLINE unsafeModify #-}
352+
unsafeModify = G.unsafeModify
353+
344354
-- | Swap the elements at the given positions. No bounds checks are performed.
345355
unsafeSwap :: PrimMonad m => MVector (PrimState m) a -> Int -> Int -> m ()
346356
{-# INLINE unsafeSwap #-}

Data/Vector/Primitive/Mutable.hs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ module Data.Vector.Primitive.Mutable (
4040
clear,
4141

4242
-- * Accessing individual elements
43-
read, write, swap,
44-
unsafeRead, unsafeWrite, unsafeSwap,
43+
read, write, modify, swap,
44+
unsafeRead, unsafeWrite, unsafeModify, unsafeSwap,
4545

4646
-- * Modifying vectors
4747

@@ -259,6 +259,11 @@ write :: (PrimMonad m, Prim a) => MVector (PrimState m) a -> Int -> a -> m ()
259259
{-# INLINE write #-}
260260
write = G.write
261261

262+
-- | Modify the element at the given position.
263+
modify :: (PrimMonad m, Prim a) => MVector (PrimState m) a -> (a -> a) -> Int -> m ()
264+
{-# INLINE modify #-}
265+
modify = G.modify
266+
262267
-- | Swap the elements at the given positions.
263268
swap :: (PrimMonad m, Prim a) => MVector (PrimState m) a -> Int -> Int -> m ()
264269
{-# INLINE swap #-}
@@ -276,6 +281,11 @@ unsafeWrite
276281
{-# INLINE unsafeWrite #-}
277282
unsafeWrite = G.unsafeWrite
278283

284+
-- | Modify the element at the given position. No bounds checks are performed.
285+
unsafeModify :: (PrimMonad m, Prim a) => MVector (PrimState m) a -> (a -> a) -> Int -> m ()
286+
{-# INLINE unsafeModify #-}
287+
unsafeModify = G.unsafeModify
288+
279289
-- | Swap the elements at the given positions. No bounds checks are performed.
280290
unsafeSwap
281291
:: (PrimMonad m, Prim a) => MVector (PrimState m) a -> Int -> Int -> m ()

Data/Vector/Storable/Mutable.hs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ module Data.Vector.Storable.Mutable(
4040
clear,
4141

4242
-- * Accessing individual elements
43-
read, write, swap,
44-
unsafeRead, unsafeWrite, unsafeSwap,
43+
read, write, modify, swap,
44+
unsafeRead, unsafeWrite, unsafeModify, unsafeSwap,
4545

4646
-- * Modifying vectors
4747

@@ -336,6 +336,11 @@ write
336336
{-# INLINE write #-}
337337
write = G.write
338338

339+
-- | Modify the element at the given position.
340+
modify :: (PrimMonad m, Storable a) => MVector (PrimState m) a -> (a -> a) -> Int -> m ()
341+
{-# INLINE modify #-}
342+
modify = G.modify
343+
339344
-- | Swap the elements at the given positions.
340345
swap
341346
:: (PrimMonad m, Storable a) => MVector (PrimState m) a -> Int -> Int -> m ()
@@ -354,6 +359,11 @@ unsafeWrite
354359
{-# INLINE unsafeWrite #-}
355360
unsafeWrite = G.unsafeWrite
356361

362+
-- | Modify the element at the given position. No bounds checks are performed.
363+
unsafeModify :: (PrimMonad m, Storable a) => MVector (PrimState m) a -> (a -> a) -> Int -> m ()
364+
{-# INLINE unsafeModify #-}
365+
unsafeModify = G.unsafeModify
366+
357367
-- | Swap the elements at the given positions. No bounds checks are performed.
358368
unsafeSwap
359369
:: (PrimMonad m, Storable a) => MVector (PrimState m) a -> Int -> Int -> m ()

Data/Vector/Unboxed/Mutable.hs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ module Data.Vector.Unboxed.Mutable (
4444
unzip, unzip3, unzip4, unzip5, unzip6,
4545

4646
-- * Accessing individual elements
47-
read, write, swap,
48-
unsafeRead, unsafeWrite, unsafeSwap,
47+
read, write, modify, swap,
48+
unsafeRead, unsafeWrite, unsafeModify, unsafeSwap,
4949

5050
-- * Modifying vectors
5151

@@ -211,6 +211,11 @@ write :: (PrimMonad m, Unbox a) => MVector (PrimState m) a -> Int -> a -> m ()
211211
{-# INLINE write #-}
212212
write = G.write
213213

214+
-- | Modify the element at the given position.
215+
modify :: (PrimMonad m, Unbox a) => MVector (PrimState m) a -> (a -> a) -> Int -> m ()
216+
{-# INLINE modify #-}
217+
modify = G.modify
218+
214219
-- | Swap the elements at the given positions.
215220
swap :: (PrimMonad m, Unbox a) => MVector (PrimState m) a -> Int -> Int -> m ()
216221
{-# INLINE swap #-}
@@ -228,6 +233,11 @@ unsafeWrite
228233
{-# INLINE unsafeWrite #-}
229234
unsafeWrite = G.unsafeWrite
230235

236+
-- | Modify the element at the given position. No bounds checks are performed.
237+
unsafeModify :: (PrimMonad m, Unbox a) => MVector (PrimState m) a -> (a -> a) -> Int -> m ()
238+
{-# INLINE unsafeModify #-}
239+
unsafeModify = G.unsafeModify
240+
231241
-- | Swap the elements at the given positions. No bounds checks are performed.
232242
unsafeSwap
233243
:: (PrimMonad m, Unbox a) => MVector (PrimState m) a -> Int -> Int -> m ()

0 commit comments

Comments
 (0)