unfoldM -package:streaming-bytestring
A monadic unfold.
Subject to fusion
Since 1.1.2
Unfold a cofree comonad from a seed, monadically.
Unfold a free monad from a seed, monadically.
Unfold a free monad from a seed, monadically.
The supplied
Maybe expression will be repeatedly called until
it returns
Nothing. All values returned are collected into a
list.
unfoldM f seed builds an
InputStream from successively
applying
f to the
seed value, continuing if
f produces
Just and halting on
Nothing.
ghci> is <- Streams.unfoldM (n -> return $ if n < 3 then Just (n, n + 1) else Nothing) 0
ghci> Streams.toList is
[0,1,2]
Construct by unfolding a monadic data structure
This is the most memory-efficient way to construct ListT where the
length depends on the inner monad.
This is unfoldM from monad-loops. It repeatedly runs an IO action
until it return Nothing, and puts all the Justs in a list. If you find
yourself using more functionality from monad-loops, just add the
package dependency instead of copying more code from it.
Create an
Automaton from a state and an effectful step
function.
The supplied
Maybe expression will be repeatedly called until
it returns
Nothing. All values returned are collected into an
arbitrary
MonadPlus thing.
The supplied
Maybe expression will be repeatedly called until
it returns
Nothing. All values returned are discarded.
Like
concatMap but uses an
Unfold for stream generation.
Unlike
concatMap this can fuse the
Unfold code with the
inner loop and therefore provide many times better performance.
Like
unfoldMany but interleaves the streams in the same way as
interleave behaves instead of appending them.
Pre-release
Unfold
Mu.
>>> unfoldMu (\i -> if i < 4 then Cons i (i + 1) else Nil) (0 :: Int)
unfoldMu unFix (Fix (Cons 0 (Fix (Cons 1 (Fix (Cons 2 (Fix (Cons 3 (Fix Nil)))))))))
A
Mealy machine modeled with explicit state.
Construct a Moore machine from a state valuation and transition
function
Construct a MooreT machine from a state valuation and transition
action
Deprecated: Please use unfoldEach instead.
Unfold and flatten the input stream of a fold.
Stream.fold (unfoldMany u f) = Stream.fold f . Stream.unfoldMany u
Pre-release
Unfold and flatten the input stream of a scan.
Stream.scanl (unfoldMany u f) == Stream.scanl f . Stream.unfoldMany u
Pre-release
A monadic unfold which does not interact with the result. The only
action this function provides therefore is to iterate through the
values in s and produce side-effects in IO.