iterateM -package:streamly

Iterate a monadic function from a seed value, streaming the results forever
Generate an infinite stream with the first element generated by the action m and each successive element derived by applying the monadic function f on the previous element.
>>> :{
Stream.iterateM (\x -> print x >> return (x + 1)) (return 0)
& Stream.take 3
& Stream.toList
:}
0
1
[0,1,2]
Generates an infinite stream starting with the given seed and applying the given function repeatedly.
>>> iterateM f m = m >>= \a -> return a `StreamK.consM` iterateM f (f a)
Generate an infinite stream with the first element generated by the action m and each successive element derived by applying the monadic function f on the previous element.
>>> :{
StreamK.iterateM (\x -> print x >> return (x + 1)) (return 0)
& StreamK.take 3
& StreamK.toList
:}
0
1
[0,1,2]
Monadic equivalent to iterate. Note that it will not terminate, but may still be useful in the main event loop of a program, for example.
Monadic version of iterate. Can be used to produce trees given a children of node function.
import Data.List.Tree (bfsLayers)
take 3 $ bfsLayers (iterateM (\i -> [i*2, i*2+1]) [1] :: ListT [] Int)
[[1],[2,3],[4,5,6,7]]
Monadic version of iterate.
Execute an action forever, feeding the result of each execution as the input to the next.
Apply a function n times to a value and construct a mutable array where each consecutive element is the result of an additional application of this function. The zeroth element is the original value.
Apply a monadic function n times to a value and construct a mutable array where each consecutive element is the result of an additional application of this function. The zeroth element is the original value.
Monadic equivalent to iterate, which uses Maybe to know when to terminate.
A version of iterate that can choose to terminate and stop by returning Nothing.
Iterate a fold generator on a stream. The initial value b is used to generate the first fold, the fold is applied on the stream and the result of the fold is used to generate the next fold and so on.
>>> import Data.Monoid (Sum(..))

>>> f x = return (Fold.take 2 (Fold.sconcat x))

>>> s = fmap Sum $ Stream.fromList [1..10]

>>> Stream.fold Fold.toList $ fmap getSum $ Stream.foldIterateM f (pure 0) s
[3,10,21,36,55,55]
This is the streaming equivalent of monad like sequenced application of folds where next fold is dependent on the previous fold. Pre-release
Like foldIterateM but using the Refold type instead. This could be much more efficient due to stream fusion. Internal
Preprocessor for Markdown.
Not on Stackage, so not searched. Converter to convert from .lhs to .md and vice versa.