streamly-0.8.1.1: Dataflow programming and declarative concurrency
Copyright(c) 2021 Composewell Technologies
LicenseBSD-3-Clause
Maintainerstreamly@composewell.com
Stabilityexperimental
PortabilityGHC
Safe HaskellNone
LanguageHaskell2010

Streamly.Internal.Data.Producer.Source

Description

A Source is a seed that can be unfolded to a stream with a buffer. Allows to unread data i.e. push unused data back to the source buffer. This is useful in parsing applications with backtracking.

Synopsis

Documentation

data Source a b Source #

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

Creation

source :: Maybe a -> Source a b Source #

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

Pre-release

Transformation

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

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

Pre-release

Consumption

isEmpty :: Source a b -> Bool Source #

Determine if the source is empty.

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

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

Pre-release

Parsing

parse :: MonadThrow m => Parser m a b -> Producer m (Source s a) a -> Source s a -> m (b, Source s a) Source #

Parse a buffered source using a parser, returning the parsed value and the remaining source.

Pre-release

parseMany :: MonadThrow m => Parser m a b -> Producer m (Source x a) a -> Producer m (Source x a) b Source #

Apply a parser repeatedly on a buffered source producer to generate a producer of parsed values.

Pre-release

parseManyD :: MonadThrow m => Parser m a b -> Producer m (Source x a) a -> Producer m (Source x a) b Source #