iteratee-0.3.5: Iteratee-based I/O

Data.Iteratee.Char

Contents

Description

Utilties for Char-based iteratee processing.

Synopsis

Type synonyms

type Stream = StreamG [] Char

A particular instance of StreamG: the stream of characters. This stream is used by many input parsers.

type EnumeratorM m a = EnumeratorGM [] Char m a

type Line = String

Word and Line processors

line :: Monad m => IterateeG [] Char m (Either Line Line)

Read the line of text from the stream The line can be terminated by CR, LF or CRLF. Return (Right Line) if successful. Return (Left Line) if EOF or a stream error were encountered before the terminator is seen. The returned line is the string read so far.

printLines :: IterateeG [] Char IO ()

Print lines as they are received. This is the first impure iteratee with non-trivial actions during chunk processing

readLines :: Monad m => IterateeG [] Char m (Either [Line] [Line])

Read a sequence of lines from the stream up to the empty lin The line can be terminated by CR, LF, or CRLF -- or by EOF or stream error. Return the read lines, in order, not including the terminating empty line Upon EOF or stream error, return the complete, terminated lines accumulated so far.

enumLines :: (ListLike (s el) el, StringLike (s el), Functor m, Monad m) => IterateeG [] (s el) m a -> IterateeG s el m (IterateeG [] (s el) m a)

Convert the stream of characters to the stream of lines, and apply the given iteratee to enumerate the latter. The stream of lines is normally terminated by the empty line. When the stream of characters is terminated, the stream of lines is also terminated, abnormally. This is the first proper iteratee-enumerator: it is the iteratee of the character stream and the enumerator of the line stream.

enumWords :: (ListLike (s el) el, StringLike (s el), Functor m, Monad m) => IterateeG [] (s el) m a -> IterateeG s el m (IterateeG [] (s el) m a)

Convert the stream of characters to the stream of words, and apply the given iteratee to enumerate the latter. Words are delimited by white space. This is the analogue of List.words One should keep in mind that enumWords is a more general, monadic function.