@@ -994,12 +994,12 @@ getIndexUnsafe i MutArray{..} = do
994994-- | /O(1)/ Lookup the element at the given index. Index starts from 0.
995995--
996996{-# INLINE getIndex #-}
997−getIndex :: forall m a. (MonadIO m, Unbox a) => Int -> MutArray a -> m a
997+getIndex :: forall m a. (MonadIO m, Unbox a) => Int -> MutArray a -> m (Maybe a)
998998getIndex i MutArray{..} = do
999999 let index = INDEX_OF(arrStart,i,a)
10001000 if i >= 0 && INDEX_VALID(index,arrEnd,a)
1001− then liftIO $ peekWith arrContents index
1002− else invalidIndex "getIndex" i
1001+ then liftIO $ Just <$> peekWith arrContents index
1002+ else return Nothing
10031003
10041004-- | /O(1)/ Lookup the element at the given index from the end of the array.
10051005-- Index starts from 0.
@@ -1038,7 +1038,9 @@ getIndicesD liftio (D.Stream stepi sti) = Unfold step inject
10381038 case r of
10391039 D.Yield i s -> do
10401040 x <- liftio $ getIndex i (MutArray contents start end undefined)
1041− return $ D.Yield x (GetIndicesState contents start end s)
1041+ case x of
1042+ Just v -> return $ D.Yield v (GetIndicesState contents start end s)
1043+ Nothing -> error "Invalid Index"
10421044 D.Skip s -> return $ D.Skip (GetIndicesState contents start end s)
10431045 D.Stop -> return D.Stop
10441046