streamly-core-0.1.0: Streaming, parsers, arrays and more
Copyright(c) 2021 Composewell Technologies
LicenseBSD-3-Clause
Maintainerstreamly@composewell.com
Stabilityexperimental
PortabilityGHC
Safe HaskellSafe-Inferred
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 :: Monad m => Parser a m b -> Producer m (Source s a) a -> Source s a -> m (Either ParseError b, Source s a) Source #

parseMany :: Monad m => Parser a m b -> Producer m (Source x a) a -> Producer m (Source x a) (Either ParseError b) Source #

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

Pre-release

parseManyD :: Monad m => Parser a m b -> Producer m (Source x a) a -> Producer m (Source x a) (Either ParseError b) Source #