on master help sign in
Make readIndex pure.
47ede46Pranay Sashank
src/Streamly/Memory/Array.hs+6−6
@@ -240,7 +240,7 @@ _null :: Storable a => Array a -> Bool
240_null arr = length arr == 0
240_null arr = length arr == 0
241
241
242{-# INLINE _last #-}
242{-# INLINE _last #-}
243−_last :: (MonadIO m, Storable a) => Array a -> m (Maybe a)
243+_last :: Storable a => Array a -> Maybe a
244_last arr = readIndex arr (length arr - 1)
244_last arr = readIndex arr (length arr - 1)
245
245
246-------------------------------------------------------------------------------
246-------------------------------------------------------------------------------
@@ -343,16 +343,16 @@ foldbWith level f = undefined
343-- Random reads and writes
343-- Random reads and writes
344-------------------------------------------------------------------------------
344-------------------------------------------------------------------------------
345
345
346−-- | /O(1)/ Lookup the element at the given index.
346+-- | /O(1)/ Lookup the element at the given index, starting from 0.
347--
347--
348-- @since 0.7.0
348-- @since 0.7.0
349{-# INLINE readIndex #-}
349{-# INLINE readIndex #-}
350−readIndex :: (MonadIO m, Storable a) => Array a -> Int -> m (Maybe a)
350+readIndex :: Storable a => Array a -> Int -> Maybe a
351readIndex arr i =
351readIndex arr i =
352 if i < 0 || i > length arr - 1
352 if i < 0 || i > length arr - 1
353− then return Nothing
353+ then Nothing
354− else liftIO $ withForeignPtr (aStart arr) $ \p ->
354+ else A.unsafeInlineIO $
355− fmap Just $ peekElemOff p i
355+ withForeignPtr (aStart arr) $ \p -> fmap Just $ peekElemOff p i
356
356
357{-
357{-
358-- | @readSlice arr i count@ streams a slice of the array @arr@ starting
358-- | @readSlice arr i count@ streams a slice of the array @arr@ starting