@@ -43,7 +43,7 @@ module Data.Vector.Unboxed.Mutable (
43
43
unzip , unzip3 , unzip4 , unzip5 , unzip6 ,
44
44
45
45
-- * Accessing individual elements
46
- read , write , modify , modifyM , swap , exchange ,
46
+ read , readMaybe , write , modify , modifyM , swap , exchange ,
47
47
unsafeRead , unsafeWrite , unsafeModify , unsafeModifyM , unsafeSwap , unsafeExchange ,
48
48
49
49
-- * Folds
@@ -293,11 +293,36 @@ clear = G.clear
293
293
-- Accessing individual elements
294
294
-- -----------------------------
295
295
296
- -- | Yield the element at the given position.
296
+ -- | Yield the element at the given position. Will throw an exception if
297
+ -- the index is out of range.
298
+ --
299
+ -- ==== __Examples__
300
+ --
301
+ -- >>> import qualified Data.Vector.Unboxed.Mutable as MVU
302
+ -- >>> v <- MVU.generate 10 (\x -> x*x)
303
+ -- >>> MVU.read v 3
304
+ -- 9
297
305
read :: (PrimMonad m , Unbox a ) => MVector (PrimState m ) a -> Int -> m a
298
306
{-# INLINE read #-}
299
307
read = G. read
300
308
309
+ -- | Yield the element at the given position. Returns 'Nothing' if
310
+ -- the index is out of range.
311
+ --
312
+ -- @since 0.13
313
+ --
314
+ -- ==== __Examples__
315
+ --
316
+ -- >>> import qualified Data.Vector.Unboxed.Mutable as MVU
317
+ -- >>> v <- MVU.generate 10 (\x -> x*x)
318
+ -- >>> MVU.readMaybe v 3
319
+ -- Just 9
320
+ -- >>> MVU.readMaybe v 13
321
+ -- Nothing
322
+ readMaybe :: (PrimMonad m , Unbox a ) => MVector (PrimState m ) a -> Int -> m (Maybe a )
323
+ {-# INLINE readMaybe #-}
324
+ readMaybe = G. readMaybe
325
+
301
326
-- | Replace the element at the given position.
302
327
write :: (PrimMonad m , Unbox a ) => MVector (PrimState m ) a -> Int -> a -> m ()
303
328
{-# INLINE write #-}
0 commit comments