Copyright | © 2015 Patryk Zadarnowski <pat@jantar.org> |
---|---|
License | BSD3 |
Maintainer | pat@jantar.org |
Stability | experimental |
Portability | portable |
Safe Haskell | Safe |
Language | Haskell2010 |
This module defines a set of functions that convert between
the Pipes and Data.Enumerator paradigms. The conversion
is bidirectional: an appropriately-typed pipe can be converted
into an Iteratee
and back into a pipe. In addition, a pipe
can be fed into an iteratee (or, more specifically, Step
),
resulting in an Enumerator
.
The library has been designed specifically for use with Snap, but I'm sure that many other interesting uses of it exist.
- fromStream :: Stream a -> Maybe [a]
- toStream :: Maybe [a] -> Stream a
- toSingletonStream :: Maybe a -> Stream a
- iterateeToPipe :: Monad m => Iteratee a m r -> P.Proxy () (Maybe a) b' b m (Either SomeException (r, Maybe [a]))
- stepToPipe :: Monad m => Step a m r -> P.Proxy () (Maybe a) b' b m (Either SomeException (r, Maybe [a]))
- pipeToIteratee :: Monad m => P.Proxy a' (Maybe a) () b m r -> Iteratee a m r
- pipeToEnumerator :: Monad m => P.Proxy a' (Maybe a) () b m r' -> Step b m r -> Iteratee a m r
Documentation
fromStream :: Stream a -> Maybe [a] Source
Converts a Stream
to an optional list.
toSingletonStream :: Maybe a -> Stream a Source
Converts an optional value to a singleton Stream
.
iterateeToPipe :: Monad m => Iteratee a m r -> P.Proxy () (Maybe a) b' b m (Either SomeException (r, Maybe [a])) Source
stepToPipe :: Monad m => Step a m r -> P.Proxy () (Maybe a) b' b m (Either SomeException (r, Maybe [a])) Source
pipeToEnumerator :: Monad m => P.Proxy a' (Maybe a) () b m r' -> Step b m r -> Iteratee a m r Source
Feed the output of a Pipe
to a Step
, effectively converting it into
an Enumerator
, generalised slightly to allow distinct input and output
types. The chunks of the input stream are fed into the pipe one element at
the time, and the pipe's output is fed to the iteratee one element per chunk.
Once the input reaches EOF
, the pipe is fed an infinite stream of Nothing
until it ends with a pure value, which is discarded. In effect, both the pipe
and the iteratee are always consumed fully.