@@ -87,6 +87,7 @@ module Streamly.Internal.Data.Array.Generic.Mut.Type
8787 -- ** Unfolds
8888 , reader
8989 -- , readerRev
90+ , producerWith -- experimental
9091 , producer -- experimental
9192
9293 -- ** To containers
@@ -545,9 +546,9 @@ writeN n = FL.take n $ writeNUnsafe n
545546
546547-- | Resumable unfold of an array.
547548--
548−{-# INLINE_NORMAL producer #-}
549−producer :: MonadIO m => Producer m (Array a) a
550−producer = Producer step inject extract
549+{-# INLINE_NORMAL producerWith #-}
550+producerWith :: Monad m => (forall b. IO b -> m b) -> Producer m (Array a) a
551+producerWith liftio = Producer step inject extract
551552
552553 where
553554
@@ -562,9 +563,15 @@ producer = Producer step inject extract
562563 step (arr, i)
563564 | assert (arrLen arr >= 0) (i == arrLen arr) = return D.Stop
564565 step (arr, i) = do
565− x <- getIndexUnsafe arr i
566+ x <- liftio $ getIndexUnsafe arr i
566567 return $ D.Yield x (arr, i + 1)
567568
569+-- | Resumable unfold of an array.
570+--
571+{-# INLINE_NORMAL producer #-}
572+producer :: MonadIO m => Producer m (Array a) a
573+producer = producerWith liftIO
574+
568575-- | Unfold an array into a stream.
569576--
570577{-# INLINE_NORMAL reader #-}