unfoldM -package:streamly

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]
O(n) The unfoldM function is analogous to the Stream unfoldr. unfoldM builds a ByteStream from a seed value. The function takes the element and returns Nothing if it is done producing the ByteStream or returns Just (a,b), in which case, a is a prepending to the ByteStream and b is used as the next element in a recursive call.
cycle ties a finite ByteStream into a circular one, or equivalently, the infinite repetition of the original ByteStream. | O(n) The unfoldM function is analogous to the Stream 'unfoldr'. unfoldM builds a ByteStream from a seed value. The function takes the element and returns Nothing if it is done producing the ByteStream or returns Just (a,b), in which case, a is a prepending to the ByteStream and b is used as the next element in a recursive call.
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.
A monadic unfold.
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.
Given some continual monadic action that produces strict ByteString chunks, produce a stream of bytes.
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.