@@ -24,6 +24,7 @@ module Streamly.Prelude
2424 , unfoldr
2525 , unfoldrM
2626 , each
27+ , iterate
2728
2829 -- * Elimination
2930 -- ** General Folds
@@ -85,7 +86,8 @@ import Prelude hiding (filter, drop, dropWhile, take,
8586 mapM, mapM_, sequence, all, any,
8687 sum, product, elem, notElem,
8788 maximum, minimum, head, last,
88− tail, length, null, reverse)
89+ tail, length, null, reverse,
90+ iterate)
8991import qualified Prelude
9092import qualified System.IO as IO
9193
@@ -120,6 +122,11 @@ unfoldrM step = fromStream . go
120122each :: (Streaming t, Foldable f) => f a -> t m a
121123each = Prelude.foldr cons nil
122124
125+iterate :: Streaming t => (a -> a) -> a -> t m a
126+iterate f = fromStream . go
127+ where
128+ go s = scons s (Just (go (f s)))
129+
123130-- | Read lines from an IO Handle into a stream of Strings.
124131fromHandle :: (Streaming t, MonadIO m) => IO.Handle -> t m String
125132fromHandle h = fromStream go