@@ -994,12 +994,12 @@ getIndexUnsafe i MutArray{..} = do
994-- | /O(1)/ Lookup the element at the given index. Index starts from 0.
994-- | /O(1)/ Lookup the element at the given index. Index starts from 0.
996{-# INLINE getIndex #-}
996{-# 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)
998getIndex i MutArray{..} = do
998getIndex i MutArray{..} = do
999 let index = INDEX_OF(arrStart,i,a)
999 let index = INDEX_OF(arrStart,i,a)
1000 if i >= 0 && INDEX_VALID(index,arrEnd,a)
1000 if i >= 0 && INDEX_VALID(index,arrEnd,a)
1001− then liftIO $ peekWith arrContents index
1001+ then liftIO $ Just <$> peekWith arrContents index
1002− else invalidIndex "getIndex" i
1002+ else return Nothing
1004-- | /O(1)/ Lookup the element at the given index from the end of the array.
1004-- | /O(1)/ Lookup the element at the given index from the end of the array.
1005-- Index starts from 0.
1005-- Index starts from 0.
@@ -1038,7 +1038,9 @@ getIndicesD liftio (D.Stream stepi sti) = Unfold step inject
1038 case r of
1038 case r of
1039 D.Yield i s -> do
1039 D.Yield i s -> do
1040 x <- liftio $ getIndex i (MutArray contents start end undefined)
1040 x <- liftio $ getIndex i (MutArray contents start end undefined)
1041− return $ D.Yield x (GetIndicesState contents start end s)
1042+ Just v -> return $ D.Yield v (GetIndicesState contents start end s)
1043+ Nothing -> error "Invalid Index"
1042 D.Skip s -> return $ D.Skip (GetIndicesState contents start end s)
1044 D.Skip s -> return $ D.Skip (GetIndicesState contents start end s)
1043 D.Stop -> return D.Stop
1045 D.Stop -> return D.Stop