@@ -177,6 +177,9 @@ module Streamly.Internal.Data.Unfold
177 , fromList
177 , fromList
178 , fromListM
178 , fromListM
180 , fromStreamK
183 , fromStreamK
181 , fromStreamD
184 , fromStreamD
@@ -260,6 +263,8 @@ module Streamly.Internal.Data.Unfold
266+#include "ArrayMacros.h"
263import Control.Exception (Exception, mask_)
268import Control.Exception (Exception, mask_)
264import Control.Monad.Catch (MonadCatch)
269import Control.Monad.Catch (MonadCatch)
265import Data.Functor (($>))
270import Data.Functor (($>))
@@ -282,6 +287,9 @@ import Streamly.Internal.Data.Unfold.Type
282import Prelude
287import Prelude
283 hiding (map, mapM, takeWhile, take, filter, const, zipWith
288 hiding (map, mapM, takeWhile, take, filter, const, zipWith
284 , drop, dropWhile, either)
289 , drop, dropWhile, either)
290+import Control.Monad.IO.Class (MonadIO (liftIO))
291+import Foreign (Storable, peek, sizeOf)
287-- >>> import qualified Streamly.Data.Fold as Fold
295-- >>> import qualified Streamly.Data.Fold as Fold
@@ -627,6 +635,18 @@ fromListM = Unfold step pure
627 step (x:xs) = (`Yield` xs) <$> x
635 step (x:xs) = (`Yield` xs) <$> x
628 step [] = pure Stop
636 step [] = pure Stop
638+{-# INLINE fromPtr #-}
639+fromPtr :: forall m a. (MonadIO m, Storable a) => Unfold m (Int, Ptr a) a
640+fromPtr = Unfold step return
644+ {-# INLINE_LATE step #-}
645+ step (0, _) = return Stop
647+ x <- liftIO $ peek p
648+ return $ Yield x (n - 1, PTR_NEXT(p, a))
630------------------------------------------------------------------------------
650------------------------------------------------------------------------------
631-- Specialized Generation
651-- Specialized Generation
632------------------------------------------------------------------------------
652------------------------------------------------------------------------------