HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulestreamly-core-0.2.2Haskell2010

Streamly.Internal.Data.Producer

A Producer is an Unfold with an extract function added to extract the state. It is more powerful but less general than an Unfold.

A Producer represents steps of a loop generating a sequence of elements. While unfolds are closed representation of imperative loops with some opaque internal state, producers are open loops with the state being accessible to the user.

Unlike an unfold, which runs a loop till completion, a producer can be stopped in the middle, its state can be extracted, examined, changed, and then it can be resumed later from the stopped state.

A producer can be used in places where a CPS stream would otherwise be needed, because the state of the loop can be passed around. However, it can be much more efficient than CPS because it allows stream fusion and unecessary function calls can be avoided.

  • 3 types
  • 16 values
datadata Source a b
#

A seed with a buffer. It allows us to unread or return some data after reading it. Useful in backtracked parsing.

valueproducer :: Monad m => Producer m a b -> Producer m (Source a b) b
#

Convert a producer to a producer from a buffered source. Any buffered data is read first and then the seed is unfolded.

Pre-release

valuesource :: Maybe a -> Source a b
#

Make a source from a seed value. The buffer would start as empty.

Pre-release

valueunread :: [b] -> Source a b -> Source a b
#

Return some unused data back to the source. The data is prepended (or consed) to the source.

Pre-release

datadata Producer (m :: Type -> Type) a b
#

A Producer m a b is a generator of a stream of values of type b from a seed of type a in Monad m.

Pre-release

Constructors

  • forall s. Producer (s -> m (Step s b)) (a -> m s) (s -> m a)
    Producer step inject extract
Instances1Functor
  • Functor m => Functor (Producer m a)Defined in streamly-core-0.2.2 · Streamly.Internal.Data.Producer.Type

    Maps a function on the output of the producer (the type b).

valuelmap :: (a -> a) -> Producer m a b -> Producer m a b
#

Map the producer input to another value of the same type.

Pre-release

Converting

2 declarations