unfoldM -package:list-t

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.
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.
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
Like unfoldMany but executes the streams in the same way as roundrobin. 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