-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Implementation of Oleg Kiselyov's left-fold enumerators -- -- Based on Oleg Kiselyov's IterateeM: -- http://okmij.org/ftp/Haskell/Iteratee/IterateeM.hs @package enumerator @version 0.2 -- | An implementation of Oleg Kiselyov’s left-fold enumerators module Data.Enumerator -- | Not to be confused with types from the Stream or -- stream-fusion packages, a Stream is a sequence of -- chunks generated by an Enumerator. In contrast to Oleg’s -- implementation, this stream does not support error handling -- errors -- encountered while generating a stream are reported in the Step -- type instead. -- -- (Chunks []) is used to indicate that a stream is still -- active, but currently has no available data. Iteratees should ignore -- empty chunks. data Stream a Chunks :: [a] -> Stream a EOF :: Stream a data Step e a m b -- | The Iteratee is capable of accepting more input. Note that more -- input is not necessarily required; the Iteratee might be able -- to generate a value immediately if it receives EOF. Continue :: (Stream a -> Iteratee e a m b) -> Step e a m b -- | The Iteratee has received enough input to generate a result. -- Included in this value is left-over input, which can be passed to -- composed Iteratees. Yield :: b -> (Stream a) -> Step e a m b -- | The Iteratee encountered an error which prevents it from -- proceeding further. The type of error will depend on the -- Enumerator and/or Iteratee -- common choices are -- String and SomeException. Error :: e -> Step e a m b -- | The primary data type for this library, which consumes input from a -- Stream until it either generates a value or encounters an -- error. Rather than requiring all input at once, an iteratee will -- return Continue when it is capable of processing more data. -- -- In general, iteratees begin in the Continue state. As each -- chunk is passed to the continuation, the iteratee returns the next -- step: Continue for more data, Yield when it's finished, -- or Error to abort processing. newtype Iteratee e a m b Iteratee :: m (Step e a m b) -> Iteratee e a m b runIteratee :: Iteratee e a m b -> m (Step e a m b) -- | While Iteratees consume data, enumerators generate it. Since -- Iteratee is an alias for m (Step e a m -- b), Enumerators can be considered step transformers of -- type Step e a m b -> m (Step e a m b). -- -- Enumerators typically read from an external source (parser, -- handle, random generator, etc). They feed chunks into an -- Iteratee until the source runs out of data (triggering -- EOF) or the iteratee finishes processing (Yields a -- value). type Enumerator e a m b = Step e a m b -> Iteratee e a m b -- | In cases where an enumerator acts as both a source and sink, the -- resulting type is named an Enumeratee. Enumeratees have two -- input types, “outer a” (aOut) and “inner a” (aIn). type Enumeratee e aOut aIn m b = Step e aIn m b -> Iteratee e aOut m (Step e aIn m b) -- |
-- returnI x = Iteratee (return x) --returnI :: (Monad m) => Step e a m b -> Iteratee e a m b -- |
-- yield x chunk = returnI (Yield x chunk) --yield :: (Monad m) => b -> Stream a -> Iteratee e a m b -- |
-- continue k = returnI (Continue k) --continue :: (Monad m) => (Stream a -> Iteratee e a m b) -> Iteratee e a m b -- |
-- throwError err = returnI (Error err) --throwError :: (Monad m) => e -> Iteratee e a m b catchError :: (Monad m) => Iteratee e a m b -> (e -> Iteratee e a m b) -> Iteratee e a m b -- |
-- liftI f = continue (returnI . f) --liftI :: (Monad m) => (Stream a -> Step e a m b) -> Iteratee e a m b -- | Equivalent to (>>=), but allows Iteratees with different -- input types to be composed. (>>==) :: (Monad m) => Iteratee e a m b -> (Step e a m b -> Iteratee e a' m b') -> Iteratee e a' m b' -- |
-- (==<<) = flip (>>==) --(==<<) :: (Monad m) => (Step e a m b -> Iteratee e a' m b') -> Iteratee e a m b -> Iteratee e a' m b' -- |
-- ($$) = (==<<) ---- -- This might be easier to read when passing a chain of iteratees to an -- enumerator. ($$) :: (Monad m) => (Step e a m b -> Iteratee e a' m b') -> Iteratee e a m b -> Iteratee e a' m b' -- |
-- (>==>) e1 e2 s = e1 s >>== e2 --(>==>) :: (Monad m) => Enumerator e a m b -> (Step e a m b -> Iteratee e a' m b') -> Step e a m b -> Iteratee e a' m b' -- |
-- (<==<) = flip (>==>) --(<==<) :: (Monad m) => (Step e a m b -> Iteratee e a' m b') -> Enumerator e a m b -> Step e a m b -> Iteratee e a' m b' -- | Run an iteratee until it finishes, and return either the final value -- (if it succeeded) or the error (if it failed). run :: (Monad m) => Iteratee e a m b -> m (Either e b) -- | Consume all input until EOF, then return consumed input as a -- list. consume :: (Monad m) => Iteratee e a m [a] -- | Return True if the next Stream is EOF. isEOF :: (Monad m) => Iteratee e a m Bool -- | Lift an Iteratee onto a monad transformer, re-wrapping the -- Iteratee’s inner monadic values. liftTrans :: (Monad m, MonadTrans t, Monad (t m)) => Iteratee e a m b -> Iteratee e a (t m) b -- | Lifts a pure left fold into an iteratee. liftFoldL :: (Monad m) => (b -> a -> b) -> b -> Iteratee e a m b -- | As liftFoldL, but strict in its accumulator. liftFoldL' :: (Monad m) => (b -> a -> b) -> b -> Iteratee e a m b -- | Lifts a monadic left fold into an iteratee. liftFoldM :: (Monad m) => (b -> a -> m b) -> b -> Iteratee e a m b -- | Print chunks as they're received from the enumerator, optionally -- printing empty chunks. printChunks :: (MonadIO m, Show a) => Bool -> Iteratee e a m () -- | The most primitive enumerator; simply sends EOF. The iteratee -- must either yield a value or throw an error continuing receiving -- EOF will not terminate with any useful value. enumEOF :: (Monad m) => Enumerator e a m b -- | Another small, useful enumerator separates an input list into chunks, -- and sends them to the iteratee. This is useful for testing iteratees -- in pure code. enumList :: (Monad m) => Integer -> [a] -> Enumerator e a m b -- | Compose a list of Enumerators using '(>>==)' concatEnums :: (Monad m) => [Enumerator e a m b] -> Enumerator e a m b -- | A common pattern in Enumeratee implementations is to check -- whether the inner Iteratee has finished, and if so, to return -- its output. checkDone passes its parameter a continuation if -- the Iteratee can still consume input, or yields otherwise. checkDone :: (Monad m) => ((Stream a -> Iteratee e a m b) -> Iteratee e a' m (Step e a m b)) -> Enumeratee e a' a m b map :: (Monad m) => (ao -> ai) -> Enumeratee e ao ai m b sequence :: (Monad m) => Iteratee e ao m ai -> Enumeratee e ao ai m b -- | joinI is used to “flatten” Enumeratees into an -- Iteratee. joinI :: (Monad m) => Iteratee e a m (Step e a' m b) -> Iteratee e a m b head :: (Monad m) => Iteratee e a m (Maybe a) peek :: (Monad m) => Iteratee e a m (Maybe a) last :: (Monad m) => Iteratee e a m (Maybe a) length :: (Monad m) => Iteratee e a m Integer drop :: (Monad m) => Integer -> Iteratee e a m () dropWhile :: (Monad m) => (a -> Bool) -> Iteratee e a m () span :: (Monad m) => (a -> Bool) -> Iteratee e a m [a] -- |
-- break p = span (not . p) --break :: (Monad m) => (a -> Bool) -> Iteratee e a m [a] instance (Show a) => Show (Stream a) instance (Eq a) => Eq (Stream a) instance (MonadIO m) => MonadIO (Iteratee e a m) instance MonadTrans (Iteratee e a) instance (Monad m) => Applicative (Iteratee e a m) instance (Monad m) => Functor (Iteratee e a m) instance (Monad m) => Monad (Iteratee e a m) instance Monad Stream instance Functor Stream instance Monoid (Stream a) -- | Enumerator-based IO module Data.Enumerator.IO -- | Read bytes (in chunks of the given buffer size) from the handle, and -- stream them to an Iteratee. If an exception occurs during file -- IO, enumeration will stop and Error will be returned. -- Exceptions from the iteratee are not caught. -- -- This enumerator blocks until at least one byte is available from the -- handle, and might read less than the maximum buffer size in some -- cases. enumHandle :: Integer -> Handle -> Enumerator SomeException ByteString IO b -- | Opens a file path in binary mode, and passes the handle to -- enumHandle. The file will be closed when the Iteratee -- finishes. enumFile :: FilePath -> Enumerator SomeException ByteString IO b -- | Opens a file path in binary mode, and passes the handle to -- iterHandle. The file will be closed when the Iteratee -- finishes. iterFile :: FilePath -> Iteratee SomeException ByteString IO () -- | Read bytes from a stream and write them to a handle. If an exception -- occurs during file IO, enumeration will stop and Error will be -- returned. iterHandle :: Handle -> Iteratee SomeException ByteString IO () -- | Enumerator-based text IO module Data.Enumerator.Text -- | Read lines of text from the handle, and stream them to an -- Iteratee. If an exception occurs during file IO, enumeration -- will stop and Error will be returned. Exceptions from the -- iteratee are not caught. enumHandle :: Handle -> Enumerator SomeException Text IO b -- | Opens a file path in text mode, and passes the handle to -- enumHandle. The file will be closed when the Iteratee -- finishes. enumFile :: FilePath -> Enumerator SomeException Text IO b -- | Read text from a stream and write it to a handle. If an exception -- occurs during file IO, enumeration will stop and Error will be -- returned. iterHandle :: Handle -> Iteratee SomeException Text IO () -- | Opens a file path in text mode, and passes the handle to -- iterHandle. The file will be closed when the Iteratee -- finishes. iterFile :: FilePath -> Iteratee SomeException Text IO () data Codec encode :: (Monad m) => Codec -> Enumeratee SomeException Text ByteString m b decode :: (Monad m) => Codec -> Enumeratee SomeException ByteString Text m b utf8 :: Codec utf16_le :: Codec utf16_be :: Codec utf32_le :: Codec utf32_be :: Codec ascii :: Codec iso8859_1 :: Codec instance Show Codec