on master help sign in
Rearrange a few functions in Internal/Data/Unfold
b226456adithyaov
src/Streamly/Internal/Data/Unfold.hs+25−20
@@ -424,6 +424,31 @@ const m = Unfold step inject
424 inject _ = return ()
424 inject _ = return ()
425 step () = m >>= \r -> return $ Yield r ()
425 step () = m >>= \r -> return $ Yield r ()
426
426
427+
428+-- | Convert a list of pure values to a 'Stream'
429+{-# INLINE_LATE fromList #-}
430+fromList :: Monad m => Unfold m [a] a
431+fromList = Unfold step inject
432+ where
433+ inject x = return x
434+ {-# INLINE_LATE step #-}
435+ step (x:xs) = return $ Yield x xs
436+ step [] = return Stop
437+
438+-- | Convert a list of monadic values to a 'Stream'
439+{-# INLINE_LATE fromListM #-}
440+fromListM :: Monad m => Unfold m [m a] a
441+fromListM = Unfold step inject
442+ where
443+ inject x = return x
444+ {-# INLINE_LATE step #-}
445+ step (x:xs) = x >>= \r -> return $ Yield r xs
446+ step [] = return Stop
447+
448+------------------------------------------------------------------------------
449+-- Specialized Generation
450+------------------------------------------------------------------------------
451+
427-- | Generates a stream replicating the seed @n@ times.
452-- | Generates a stream replicating the seed @n@ times.
428--
453--
429{-# INLINE replicateM #-}
454{-# INLINE replicateM #-}
@@ -446,26 +471,6 @@ repeatM = Unfold step return
446 {-# INLINE_LATE step #-}
471 {-# INLINE_LATE step #-}
447 step x = return $ Yield x x
472 step x = return $ Yield x x
448
473
449−-- | Convert a list of pure values to a 'Stream'
450−{-# INLINE_LATE fromList #-}
451−fromList :: Monad m => Unfold m [a] a
452−fromList = Unfold step inject
453− where
454− inject x = return x
455− {-# INLINE_LATE step #-}
456− step (x:xs) = return $ Yield x xs
457− step [] = return Stop
458−
459−-- | Convert a list of monadic values to a 'Stream'
460−{-# INLINE_LATE fromListM #-}
461−fromListM :: Monad m => Unfold m [m a] a
462−fromListM = Unfold step inject
463− where
464− inject x = return x
465− {-# INLINE_LATE step #-}
466− step (x:xs) = x >>= \r -> return $ Yield r xs
467− step [] = return Stop
468−
469-------------------------------------------------------------------------------
474-------------------------------------------------------------------------------
470-- Filtering
475-- Filtering
471-------------------------------------------------------------------------------
476-------------------------------------------------------------------------------