on master help sign in
Add readRev to mutable array module
commit05dde8e0b6caaa0f66ac12626d6b3bf9aa2404cd authorHarendra Kumar <harendra@composewell.com> dateFri 10 Mar 2023, 14:03 (4 years ago) parent552708f
1 file changed+8−1
core/src/Streamly/Internal/Data/Array/Generic/Mut/Type.hs+8−1
core/src/Streamly/Internal/Data/Array/Generic/Mut/Type.hs+8−1
@@ -92,7 +92,7 @@ module Streamly.Internal.Data.Array.Generic.Mut.Type
9292
9393 -- ** To containers
9494 , toStreamD
95− -- , toStreamDRev
95+ , readRev
9696 , toStreamK
9797 -- , toStreamKRev
9898 , toList
@@ -536,6 +536,7 @@ toStreamD :: MonadIO m => MutArray a -> D.Stream m a
536536toStreamD arr@MutArray{..} =
537537 D.mapM (`getIndexUnsafe` arr) $ D.enumerateFromToIntegral 0 (arrLen - 1)
538538
539+-- Check equivalence with StreamK.fromStream . toStreamD and remove
539540{-# INLINE toStreamK #-}
540541toStreamK :: MonadIO m => MutArray a -> K.StreamK m a
541542toStreamK arr@MutArray{..} = K.unfoldrM step 0
@@ -548,6 +549,12 @@ toStreamK arr@MutArray{..} = K.unfoldrM step 0
548549 x <- getIndexUnsafe i arr
549550 return $ Just (x, i + 1)
550551
552+{-# INLINE_NORMAL readRev #-}
553+readRev :: MonadIO m => MutArray a -> D.Stream m a
554+readRev arr@MutArray{..} =
555+ D.mapM (`getIndexUnsafe` arr)
556+ $ D.enumerateFromThenToIntegral (arrLen - 1) (arrLen - 2) 0
557+
551558-------------------------------------------------------------------------------
552559-- Folds
553560-------------------------------------------------------------------------------