-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | Streaming data processing library.
--
-- conduit is a solution to the streaming data problem, allowing
-- for production, transformation, and consumption of streams of data in
-- constant memory. It is an alternative to lazy I/O which guarantees
-- deterministic resource handling, and fits in the same general solution
-- space as enumerator/iteratee and pipes. For
-- a tutorial, please visit
-- https://haskell.fpcomplete.com/user/snoyberg/library-documentation/conduit-overview.
--
-- Release history:
--
--
-- - 1.0 Simplified the user-facing interface back to the
-- Source, Sink, and Conduit types, with Producer and Consumer for
-- generic code. Error messages have been simplified, and optional
-- leftovers and upstream terminators have been removed from the external
-- API. Some long-deprecated functions were finally removed.
-- - 0.5 The internals of the package are now separated to the
-- .Internal module, leaving only the higher-level interface in the
-- advertised API. Internally, switched to a Leftover
-- constructor and slightly tweaked the finalization semantics.
-- - 0.4 Inspired by the design of the pipes package: we now
-- have a single unified type underlying Source, Sink,
-- and Conduit. This type is named Pipe. There are type
-- synonyms provided for the other three types. Additionally,
-- BufferedSource is no longer provided. Instead, the
-- connect-and-resume operator, $$+, can be used for the same
-- purpose.
-- - 0.3 ResourceT has been greatly simplified, specialized for
-- IO, and moved into a separate package. Instead of hard-coding
-- ResourceT into the conduit datatypes, they can now live around any
-- monad. The Conduit datatype has been enhanced to better allow
-- generation of streaming output. The SourceResult, SinkResult, and
-- ConduitResult datatypes have been removed entirely.
-- - 0.2 Instead of storing state in mutable variables, we now
-- use CPS. A Source returns the next Source, and
-- likewise for Sinks and Conduits. Not only does this
-- take better advantage of GHC's optimizations (about a 20% speedup),
-- but it allows some operations to have a reduction in algorithmic
-- complexity from exponential to linear. This also allowed us to remove
-- the Prepared set of types. Also, the State functions
-- (e.g., sinkState) use better constructors for return types,
-- avoiding the need for a dummy state on completion.
-- - 0.1 BufferedSource is now an abstract type, and
-- has a much more efficient internal representation. The result was a
-- 41% speedup on microbenchmarks (note: do not expect speedups anywhere
-- near that in real usage). In general, we are moving towards
-- BufferedSource being a specific tool used internally as
-- needed, but using Source for all external APIs.
-- - 0.0 Initial release.
--
@package conduit
@version 1.0.2
module Data.Conduit.Internal
-- | The underlying datatype for all the types in this package. In has six
-- type parameters:
--
--
-- - l is the type of values that may be left over from this
-- Pipe. A Pipe with no leftovers would use
-- Void here, and one with leftovers would use the same type as
-- the i parameter. Leftovers are automatically provided to the
-- next Pipe in the monadic chain.
-- - i is the type of values for this Pipe's input
-- stream.
-- - o is the type of values for this Pipe's output
-- stream.
-- - u is the result type from the upstream Pipe.
-- - m is the underlying monad.
-- - r is the result type.
--
--
-- A basic intuition is that every Pipe produces a stream of
-- output values (o), and eventually indicates that this stream is
-- terminated by sending a result (r). On the receiving end of a
-- Pipe, these become the i and u parameters.
--
-- Since 0.5.0
data Pipe l i o u m r
-- | Provide new output to be sent downstream. This constructor has three
-- fields: the next Pipe to be used, a finalization function,
-- and the output value.
HaveOutput :: (Pipe l i o u m r) -> (m ()) -> o -> Pipe l i o u m r
-- | Request more input from upstream. The first field takes a new input
-- value and provides a new Pipe. The second takes an upstream
-- result value, which indicates that upstream is producing no more
-- results.
NeedInput :: (i -> Pipe l i o u m r) -> (u -> Pipe l i o u m r) -> Pipe l i o u m r
-- | Processing with this Pipe is complete, providing the final
-- result.
Done :: r -> Pipe l i o u m r
-- | Require running of a monadic action to get the next Pipe.
PipeM :: (m (Pipe l i o u m r)) -> Pipe l i o u m r
-- | Return leftover input, which should be provided to future operations.
Leftover :: (Pipe l i o u m r) -> l -> Pipe l i o u m r
-- | Core datatype of the conduit package. This type represents a general
-- component which can consume a stream of input values i,
-- produce a stream of output values o, perform actions in the
-- m monad, and produce a final result r. The type
-- synonyms provided here are simply wrappers around this type.
--
-- Since 1.0.0
newtype ConduitM i o m r
ConduitM :: Pipe i i o () m r -> ConduitM i o m r
unConduitM :: ConduitM i o m r -> Pipe i i o () m r
-- | Provides a stream of output values, without consuming any input or
-- producing a final result.
--
-- Since 0.5.0
type Source m o = ConduitM () o m ()
-- | A component which produces a stream of output values, regardless of
-- the input stream. A Producer is a generalization of a
-- Source, and can be used as either a Source or a
-- Conduit.
--
-- Since 1.0.0
type Producer m o = forall i. ConduitM i o m ()
-- | Consumes a stream of input values and produces a final result, without
-- producing any output.
--
-- Since 0.5.0
type Sink i m r = ConduitM i Void m r
-- | A component which consumes a stream of input values and produces a
-- final result, regardless of the output stream. A Consumer is
-- a generalization of a Sink, and can be used as either a
-- Sink or a Conduit.
--
-- Since 1.0.0
type Consumer i m r = forall o. ConduitM i o m r
-- | Consumes a stream of input values and produces a stream of output
-- values, without producing a final result.
--
-- Since 0.5.0
type Conduit i m o = ConduitM i o m ()
-- | A Source which has been started, but has not yet completed.
--
-- This type contains both the current state of the Source, and
-- the finalizer to be run to close it.
--
-- Since 0.5.0
data ResumableSource m o
ResumableSource :: (Source m o) -> (m ()) -> ResumableSource m o
-- | Wait for a single input value from upstream.
--
-- Since 0.5.0
await :: Pipe l i o u m (Maybe i)
-- | This is similar to await, but will return the upstream result
-- value as Left if available.
--
-- Since 0.5.0
awaitE :: Pipe l i o u m (Either u i)
-- | Wait for input forever, calling the given inner Pipe for each
-- piece of new input. Returns the upstream result type.
--
-- Since 0.5.0
awaitForever :: Monad m => (i -> Pipe l i o r m r') -> Pipe l i o r m r
-- | Send a single output value downstream. If the downstream Pipe
-- terminates, this Pipe will terminate as well.
--
-- Since 0.5.0
yield :: Monad m => o -> Pipe l i o u m ()
-- | Similar to yield, but additionally takes a finalizer to be
-- run if the downstream Pipe terminates.
--
-- Since 0.5.0
yieldOr :: Monad m => o -> m () -> Pipe l i o u m ()
-- | Provide a single piece of leftover input to be consumed by the next
-- pipe in the current monadic binding.
--
-- Note: it is highly encouraged to only return leftover values
-- from input already consumed from upstream.
--
-- Since 0.5.0
leftover :: l -> Pipe l i o u m ()
-- | Perform some allocation and run an inner Pipe. Two guarantees
-- are given about resource finalization:
--
--
-- - It will be prompt. The finalization will be run as early as
-- possible.
-- - It is exception safe. Due to usage of resourcet, the
-- finalization will be run in the event of any exceptions.
--
--
-- Since 0.5.0
bracketP :: MonadResource m => IO a -> (a -> IO ()) -> (a -> Pipe l i o u m r) -> Pipe l i o u m r
-- | Add some code to be run when the given Pipe cleans up.
--
-- Since 0.4.1
addCleanup :: Monad m => (Bool -> m ()) -> Pipe l i o u m r -> Pipe l i o u m r
-- | The identity Pipe.
--
-- Since 0.5.0
idP :: Monad m => Pipe l a a r m r
-- | Compose a left and right pipe together into a complete pipe. The left
-- pipe will be automatically closed when the right pipe finishes.
--
-- Since 0.5.0
pipe :: Monad m => Pipe l a b r0 m r1 -> Pipe Void b c r1 m r2 -> Pipe l a c r0 m r2
-- | Same as pipe, but automatically applies injectLeftovers
-- to the right Pipe.
--
-- Since 0.5.0
pipeL :: Monad m => Pipe l a b r0 m r1 -> Pipe b b c r1 m r2 -> Pipe l a c r0 m r2
-- | Connect a Source to a Sink until the latter closes.
-- Returns both the most recent state of the Source and the
-- result of the Sink.
--
-- We use a ResumableSource to keep track of the most recent
-- finalizer provided by the Source.
--
-- Since 0.5.0
connectResume :: Monad m => ResumableSource m o -> Sink o m r -> m (ResumableSource m o, r)
-- | Run a pipeline until processing completes.
--
-- Since 0.5.0
runPipe :: Monad m => Pipe Void () Void () m r -> m r
-- | Transforms a Pipe that provides leftovers to one which does
-- not, allowing it to be composed.
--
-- This function will provide any leftover values within this
-- Pipe to any calls to await. If there are more
-- leftover values than are demanded, the remainder are discarded.
--
-- Since 0.5.0
injectLeftovers :: Monad m => Pipe i i o u m r -> Pipe l i o u m r
-- | Fuse together two Pipes, connecting the output from the left
-- to the input of the right.
--
-- Notice that the leftover parameter for the Pipes must
-- be Void. This ensures that there is no accidental data loss
-- of leftovers during fusion. If you have a Pipe with
-- leftovers, you must first call injectLeftovers.
--
-- Since 0.5.0
(>+>) :: Monad m => Pipe l a b r0 m r1 -> Pipe Void b c r1 m r2 -> Pipe l a c r0 m r2
-- | Same as >+>, but reverse the order of the arguments.
--
-- Since 0.5.0
(<+<) :: Monad m => Pipe Void b c r1 m r2 -> Pipe l a b r0 m r1 -> Pipe l a c r0 m r2
sourceToPipe :: Monad m => Source m o -> Pipe l i o u m ()
sinkToPipe :: Monad m => Sink i m r -> Pipe l i o u m r
conduitToPipe :: Monad m => Conduit i m o -> Pipe l i o u m ()
-- | Generalize a Source to a Producer.
--
-- Since 1.0.0
toProducer :: Monad m => Source m a -> Producer m a
-- | Generalize a Sink to a Consumer.
--
-- Since 1.0.0
toConsumer :: Monad m => Sink a m b -> Consumer a m b
-- | Transform the monad that a Pipe lives in.
--
-- Note that the monad transforming function will be run multiple times,
-- resulting in unintuitive behavior in some cases. For a fuller
-- treatment, please see:
--
--
-- https://github.com/snoyberg/conduit/wiki/Dealing-with-monad-transformers
--
-- Since 0.4.0
transPipe :: Monad m => (forall a. m a -> n a) -> Pipe l i o u m r -> Pipe l i o u n r
-- | Apply a function to all the output values of a Pipe.
--
-- This mimics the behavior of fmap for a Source and
-- Conduit in pre-0.4 days.
--
-- Since 0.4.1
mapOutput :: Monad m => (o1 -> o2) -> Pipe l i o1 u m r -> Pipe l i o2 u m r
-- | Same as mapOutput, but use a function that returns
-- Maybe values.
--
-- Since 0.5.0
mapOutputMaybe :: Monad m => (o1 -> Maybe o2) -> Pipe l i o1 u m r -> Pipe l i o2 u m r
-- | Apply a function to all the input values of a Pipe.
--
-- Since 0.5.0
mapInput :: Monad m => (i1 -> i2) -> (l2 -> Maybe l1) -> Pipe l2 i2 o u m r -> Pipe l1 i1 o u m r
-- | Convert a list into a source.
--
-- Since 0.3.0
sourceList :: Monad m => [a] -> Pipe l i a u m ()
-- | Returns a tuple of the upstream and downstream results. Note that this
-- will force consumption of the entire input stream.
--
-- Since 0.5.0
withUpstream :: Monad m => Pipe l i o u m r -> Pipe l i o u m (u, r)
-- | Unwraps a ResumableSource into a Source and a
-- finalizer.
--
-- A ResumableSource represents a Source which has
-- already been run, and therefore has a finalizer registered. As a
-- result, if we want to turn it into a regular Source, we need
-- to ensure that the finalizer will be run appropriately. By
-- appropriately, I mean:
--
--
-- - If a new finalizer is registered, the old one should not be
-- called.
-- - If the old one is called, it should not be called again.
--
--
-- This function returns both a Source and a finalizer which
-- ensures that the above two conditions hold. Once you call that
-- finalizer, the Source is invalidated and cannot be used.
--
-- Since 0.5.2
unwrapResumable :: MonadIO m => ResumableSource m o -> m (Source m o, m ())
instance Monad m => Functor (ConduitM i o m)
instance Monad m => Applicative (ConduitM i o m)
instance Monad m => Monad (ConduitM i o m)
instance MonadIO m => MonadIO (ConduitM i o m)
instance MonadTrans (ConduitM i o)
instance MonadThrow m => MonadThrow (ConduitM i o m)
instance MonadActive m => MonadActive (ConduitM i o m)
instance MonadResource m => MonadResource (ConduitM i o m)
instance Monad m => Monoid (ConduitM i o m ())
instance MonadBase base m => MonadBase base (ConduitM i o m)
instance MonadResource m => MonadResource (Pipe l i o u m)
instance Monad m => Monoid (Pipe l i o u m ())
instance MonadActive m => MonadActive (Pipe l i o u m)
instance MonadThrow m => MonadThrow (Pipe l i o u m)
instance MonadIO m => MonadIO (Pipe l i o u m)
instance MonadTrans (Pipe l i o u)
instance MonadBase base m => MonadBase base (Pipe l i o u m)
instance Monad m => Monad (Pipe l i o u m)
instance Monad m => Applicative (Pipe l i o u m)
instance Monad m => Functor (Pipe l i o u m)
-- | Utility functions from older versions of conduit. These
-- should be considered deprecated, as there are now easier ways to
-- handle their use cases. This module is provided solely for backwards
-- compatibility.
module Data.Conduit.Util
-- | Combines two sources. The new source will stop producing once either
-- source has been exhausted.
--
-- Since 0.3.0
zip :: Monad m => Source m a -> Source m b -> Source m (a, b)
-- | Combines two sinks. The new sink will complete when both input sinks
-- have completed.
--
-- Any leftovers are discarded.
--
-- Since 0.4.1
zipSinks :: Monad m => Sink i m r -> Sink i m r' -> Sink i m (r, r')
-- | If this is your first time with conduit, you should probably start
-- with the tutorial:
-- https://haskell.fpcomplete.com/user/snoyberg/library-documentation/conduit-overview.
module Data.Conduit
-- | Provides a stream of output values, without consuming any input or
-- producing a final result.
--
-- Since 0.5.0
type Source m o = ConduitM () o m ()
-- | Consumes a stream of input values and produces a stream of output
-- values, without producing a final result.
--
-- Since 0.5.0
type Conduit i m o = ConduitM i o m ()
-- | Consumes a stream of input values and produces a final result, without
-- producing any output.
--
-- Since 0.5.0
type Sink i m r = ConduitM i Void m r
-- | Core datatype of the conduit package. This type represents a general
-- component which can consume a stream of input values i,
-- produce a stream of output values o, perform actions in the
-- m monad, and produce a final result r. The type
-- synonyms provided here are simply wrappers around this type.
--
-- Since 1.0.0
data ConduitM i o m r
-- | The connect operator, which pulls data from a source and pushes to a
-- sink. If you would like to keep the Source open to be used
-- for other operations, use the connect-and-resume operator $$+.
--
-- Since 0.4.0
($$) :: Monad m => Source m a -> Sink a m b -> m b
-- | Left fuse, combining a source and a conduit together into a new
-- source.
--
-- Both the Source and Conduit will be closed when the
-- newly-created Source is closed.
--
-- Leftover data from the Conduit will be discarded.
--
-- Since 0.4.0
($=) :: Monad m => Source m a -> Conduit a m b -> Source m b
-- | Right fuse, combining a conduit and a sink together into a new sink.
--
-- Both the Conduit and Sink will be closed when the
-- newly-created Sink is closed.
--
-- Leftover data returned from the Sink will be discarded.
--
-- Since 0.4.0
(=$) :: Monad m => Conduit a m b -> Sink b m c -> Sink a m c
-- | Fusion operator, combining two Conduits together into a new
-- Conduit.
--
-- Both Conduits will be closed when the newly-created
-- Conduit is closed.
--
-- Leftover data returned from the right Conduit will be
-- discarded.
--
-- Since 0.4.0
(=$=) :: Monad m => Conduit a m b -> ConduitM b c m r -> ConduitM a c m r
-- | Wait for a single input value from upstream. If no data is available,
-- returns Nothing.
--
-- Since 0.5.0
await :: Monad m => Consumer i m (Maybe i)
-- | Send a value downstream to the next component to consume. If the
-- downstream component terminates, this call will never return control.
-- If you would like to register a cleanup function, please use
-- yieldOr instead.
--
-- Since 0.5.0
yield :: Monad m => o -> ConduitM i o m ()
-- | Provide a single piece of leftover input to be consumed by the next
-- component in the current monadic binding.
--
-- Note: it is highly encouraged to only return leftover values
-- from input already consumed from upstream.
--
-- Since 0.5.0
leftover :: i -> ConduitM i o m ()
-- | Perform some allocation and run an inner component. Two guarantees are
-- given about resource finalization:
--
--
-- - It will be prompt. The finalization will be run as early as
-- possible.
-- - It is exception safe. Due to usage of resourcet, the
-- finalization will be run in the event of any exceptions.
--
--
-- Since 0.5.0
bracketP :: MonadResource m => IO a -> (a -> IO ()) -> (a -> ConduitM i o m r) -> ConduitM i o m r
-- | Add some code to be run when the given component cleans up.
--
-- The supplied cleanup function will be given a True if the
-- component ran to completion, or False if it terminated early
-- due to a downstream component terminating.
--
-- Note that this function is not exception safe. For that, please use
-- bracketP.
--
-- Since 0.4.1
addCleanup :: Monad m => (Bool -> m ()) -> ConduitM i o m r -> ConduitM i o m r
-- | Similar to yield, but additionally takes a finalizer to be run
-- if the downstream component terminates.
--
-- Since 0.5.0
yieldOr :: Monad m => o -> m () -> ConduitM i o m ()
-- | A component which produces a stream of output values, regardless of
-- the input stream. A Producer is a generalization of a
-- Source, and can be used as either a Source or a
-- Conduit.
--
-- Since 1.0.0
type Producer m o = forall i. ConduitM i o m ()
-- | A component which consumes a stream of input values and produces a
-- final result, regardless of the output stream. A Consumer is
-- a generalization of a Sink, and can be used as either a
-- Sink or a Conduit.
--
-- Since 1.0.0
type Consumer i m r = forall o. ConduitM i o m r
-- | Generalize a Source to a Producer.
--
-- Since 1.0.0
toProducer :: Monad m => Source m a -> Producer m a
-- | Generalize a Sink to a Consumer.
--
-- Since 1.0.0
toConsumer :: Monad m => Sink a m b -> Consumer a m b
-- | Wait for input forever, calling the given inner component for each
-- piece of new input. Returns the upstream result type.
--
-- This function is provided as a convenience for the common pattern of
-- awaiting input, checking if it's Just and then
-- looping.
--
-- Since 0.5.0
awaitForever :: Monad m => (i -> ConduitM i o m r) -> ConduitM i o m ()
-- | Transform the monad that a ConduitM lives in.
--
-- Note that the monad transforming function will be run multiple times,
-- resulting in unintuitive behavior in some cases. For a fuller
-- treatment, please see:
--
--
-- https://github.com/snoyberg/conduit/wiki/Dealing-with-monad-transformers
--
-- Since 0.4.0
transPipe :: Monad m => (forall a. m a -> n a) -> ConduitM i o m r -> ConduitM i o n r
-- | Apply a function to all the output values of a ConduitM.
--
-- This mimics the behavior of fmap for a Source and
-- Conduit in pre-0.4 days. It can also be simulated by fusing
-- with the map conduit from Data.Conduit.List.
--
-- Since 0.4.1
mapOutput :: Monad m => (o1 -> o2) -> ConduitM i o1 m r -> ConduitM i o2 m r
-- | Same as mapOutput, but use a function that returns
-- Maybe values.
--
-- Since 0.5.0
mapOutputMaybe :: Monad m => (o1 -> Maybe o2) -> ConduitM i o1 m r -> ConduitM i o2 m r
-- | Apply a function to all the input values of a ConduitM.
--
-- Since 0.5.0
mapInput :: Monad m => (i1 -> i2) -> (i2 -> Maybe i1) -> ConduitM i2 o m r -> ConduitM i1 o m r
-- | A Source which has been started, but has not yet completed.
--
-- This type contains both the current state of the Source, and
-- the finalizer to be run to close it.
--
-- Since 0.5.0
data ResumableSource m o
-- | The connect-and-resume operator. This does not close the
-- Source, but instead returns it to be used again. This allows
-- a Source to be used incrementally in a large program, without
-- forcing the entire program to live in the Sink monad.
--
-- Mnemonic: connect + do more.
--
-- Since 0.5.0
($$+) :: Monad m => Source m a -> Sink a m b -> m (ResumableSource m a, b)
-- | Continue processing after usage of $$+.
--
-- Since 0.5.0
($$++) :: Monad m => ResumableSource m a -> Sink a m b -> m (ResumableSource m a, b)
-- | Complete processing of a ResumableSource. This will run the
-- finalizer associated with the ResumableSource. In order to
-- guarantee process resource finalization, you must use this
-- operator after using $$+ and $$++.
--
-- Since 0.5.0
($$+-) :: Monad m => ResumableSource m a -> Sink a m b -> m b
-- | Unwraps a ResumableSource into a Source and a
-- finalizer.
--
-- A ResumableSource represents a Source which has
-- already been run, and therefore has a finalizer registered. As a
-- result, if we want to turn it into a regular Source, we need
-- to ensure that the finalizer will be run appropriately. By
-- appropriately, I mean:
--
--
-- - If a new finalizer is registered, the old one should not be
-- called.
-- - If the old one is called, it should not be called again.
--
--
-- This function returns both a Source and a finalizer which
-- ensures that the above two conditions hold. Once you call that
-- finalizer, the Source is invalidated and cannot be used.
--
-- Since 0.5.2
unwrapResumable :: MonadIO m => ResumableSource m o -> m (Source m o, m ())
-- | Provide for a stream of data that can be flushed.
--
-- A number of Conduits (e.g., zlib compression) need the
-- ability to flush the stream at some point. This provides a single
-- wrapper datatype to be used in all such circumstances.
--
-- Since 0.3.0
data Flush a
Chunk :: a -> Flush a
Flush :: Flush a
-- | The Resource transformer. This transformer keeps track of all
-- registered actions, and calls them upon exit (via
-- runResourceT). Actions may be registered via register,
-- or resources may be allocated atomically via allocate.
-- allocate corresponds closely to bracket.
--
-- Releasing may be performed before exit via the release
-- function. This is a highly recommended optimization, as it will ensure
-- that scarce resources are freed early. Note that calling
-- release will deregister the action, so that a release action
-- will only ever be called once.
--
-- Since 0.3.0
data ResourceT (m :: * -> *) a :: (* -> *) -> * -> *
-- | A Monad which allows for safe resource allocation. In theory,
-- any monad transformer stack included a ResourceT can be an
-- instance of MonadResource.
--
-- Note: runResourceT has a requirement for a
-- MonadBaseControl IO m monad, which allows control operations
-- to be lifted. A MonadResource does not have this requirement.
-- This means that transformers such as ContT can be an instance
-- of MonadResource. However, the ContT wrapper will
-- need to be unwrapped before calling runResourceT.
--
-- Since 0.3.0
class (MonadThrow m, MonadUnsafeIO m, MonadIO m, Applicative m) => MonadResource (m :: * -> *)
-- | A Monad which can throw exceptions. Note that this does not
-- work in a vanilla ST or Identity monad. Instead, you
-- should use the ExceptionT transformer in your stack if you are
-- dealing with a non-IO base monad.
--
-- Since 0.3.0
class Monad m => MonadThrow (m :: * -> *)
monadThrow :: (MonadThrow m, Exception e) => e -> m a
-- | A Monad based on some monad which allows running of some
-- IO actions, via unsafe calls. This applies to IO and
-- ST, for instance.
--
-- Since 0.3.0
class Monad m => MonadUnsafeIO (m :: * -> *)
unsafeLiftIO :: MonadUnsafeIO m => IO a -> m a
-- | Unwrap a ResourceT transformer, and call all registered release
-- actions.
--
-- Note that there is some reference counting involved due to
-- resourceForkIO. If multiple threads are sharing the same
-- collection of resources, only the last call to runResourceT
-- will deallocate the resources.
--
-- Since 0.3.0
runResourceT :: MonadBaseControl IO m => ResourceT m a -> m a
-- | The express purpose of this transformer is to allow
-- non-IO-based monad stacks to catch exceptions via the
-- MonadThrow typeclass.
--
-- Since 0.3.0
newtype ExceptionT (m :: * -> *) a :: (* -> *) -> * -> *
ExceptionT :: m (Either SomeException a) -> ExceptionT a
runExceptionT :: ExceptionT a -> m (Either SomeException a)
-- | Same as runExceptionT, but immediately throw any
-- exception returned.
--
-- Since 0.3.0
runExceptionT_ :: Monad m => ExceptionT m a -> m a
-- | Run an ExceptionT Identity stack.
--
-- Since 0.4.2
runException :: ExceptionT Identity a -> Either SomeException a
-- | Run an ExceptionT Identity stack, but immediately
-- throw any exception returned.
--
-- Since 0.4.2
runException_ :: ExceptionT Identity a -> a
class MonadBase b m => MonadBaseControl (b :: * -> *) (m :: * -> *) | m -> b
instance Show a => Show (Flush a)
instance Eq a => Eq (Flush a)
instance Ord a => Ord (Flush a)
instance Functor Flush
-- | Higher-level functions to interact with the elements of a stream. Most
-- of these are based on list functions.
--
-- Note that these functions all deal with individual elements of a
-- stream as a sort of "black box", where there is no introspection of
-- the contained elements. Values such as ByteString and
-- Text will likely need to be treated specially to deal with
-- their contents properly (Word8 and Char,
-- respectively). See the Data.Conduit.Binary and
-- Data.Conduit.Text modules.
module Data.Conduit.List
sourceList :: Monad m => [a] -> Producer m a
-- | A source that outputs no values. Note that this is just a
-- type-restricted synonym for mempty.
--
-- Since 0.3.0
sourceNull :: Monad m => Producer m a
-- | Generate a source from a seed value.
--
-- Since 0.4.2
unfold :: Monad m => (b -> Maybe (a, b)) -> b -> Producer m a
-- | Enumerate from a value to a final value, inclusive, via succ.
--
-- This is generally more efficient than using Prelude's
-- enumFromTo and combining with sourceList since this
-- avoids any intermediate data structures.
--
-- Since 0.4.2
enumFromTo :: (Enum a, Eq a, Monad m) => a -> a -> Producer m a
-- | Produces an infinite stream of repeated applications of f to x.
iterate :: Monad m => (a -> a) -> a -> Producer m a
-- | A strict left fold.
--
-- Since 0.3.0
fold :: Monad m => (b -> a -> b) -> b -> Consumer a m b
-- | A monoidal strict left fold.
--
-- Since 0.5.3
foldMap :: (Monad m, Monoid b) => (a -> b) -> Consumer a m b
-- | Take some values from the stream and return as a list. If you want to
-- instead create a conduit that pipes data to another sink, see
-- isolate. This function is semantically equivalent to:
--
--
-- take i = isolate i =$ consume
--
--
-- Since 0.3.0
take :: Monad m => Int -> Consumer a m [a]
-- | Ignore a certain number of values in the stream. This function is
-- semantically equivalent to:
--
--
-- drop i = take i >> return ()
--
--
-- However, drop is more efficient as it does not need to hold
-- values in memory.
--
-- Since 0.3.0
drop :: Monad m => Int -> Consumer a m ()
-- | Take a single value from the stream, if available.
--
-- Since 0.3.0
head :: Monad m => Consumer a m (Maybe a)
-- | Look at the next value in the stream, if available. This function will
-- not change the state of the stream.
--
-- Since 0.3.0
peek :: Monad m => Consumer a m (Maybe a)
-- | Consume all values from the stream and return as a list. Note that
-- this will pull all values into memory. For a lazy variant, see
-- Data.Conduit.Lazy.
--
-- Since 0.3.0
consume :: Monad m => Consumer a m [a]
-- | Ignore the remainder of values in the source. Particularly useful when
-- combined with isolate.
--
-- Since 0.3.0
sinkNull :: Monad m => Consumer a m ()
-- | A monadic strict left fold.
--
-- Since 0.3.0
foldM :: Monad m => (b -> a -> m b) -> b -> Consumer a m b
-- | Apply the action to all values in the stream.
--
-- Since 0.3.0
mapM_ :: Monad m => (a -> m ()) -> Consumer a m ()
-- | Apply a transformation to all values in a stream.
--
-- Since 0.3.0
map :: Monad m => (a -> b) -> Conduit a m b
-- | Apply a transformation that may fail to all values in a stream,
-- discarding the failures.
--
-- Since 0.5.1
mapMaybe :: Monad m => (a -> Maybe b) -> Conduit a m b
-- | Filter the Just values from a stream, discarding the
-- Nothing values.
--
-- Since 0.5.1
catMaybes :: Monad m => Conduit (Maybe a) m a
-- | Apply a transformation to all values in a stream, concatenating the
-- output values.
--
-- Since 0.3.0
concatMap :: Monad m => (a -> [b]) -> Conduit a m b
-- | concatMap with an accumulator.
--
-- Since 0.3.0
concatMapAccum :: Monad m => (a -> accum -> (accum, [b])) -> accum -> Conduit a m b
-- | Grouping input according to an equality function.
--
-- Since 0.3.0
groupBy :: Monad m => (a -> a -> Bool) -> Conduit a m [a]
-- | Ensure that the inner sink consumes no more than the given number of
-- values. Note this this does not ensure that the sink consumes
-- all of those values. To get the latter behavior, combine with
-- sinkNull, e.g.:
--
--
-- src $$ do
-- x <- isolate count =$ do
-- x <- someSink
-- sinkNull
-- return x
-- someOtherSink
-- ...
--
--
-- Since 0.3.0
isolate :: Monad m => Int -> Conduit a m a
-- | Keep only values in the stream passing a given predicate.
--
-- Since 0.3.0
filter :: Monad m => (a -> Bool) -> Conduit a m a
-- | Apply a monadic transformation to all values in a stream.
--
-- If you do not need the transformed values, and instead just want the
-- monadic side-effects of running the action, see mapM_.
--
-- Since 0.3.0
mapM :: Monad m => (a -> m b) -> Conduit a m b
-- | Apply a monadic action on all values in a stream.
--
-- This Conduit can be used to perform a monadic side-effect for
-- every value, whilst passing the value through the Conduit
-- as-is.
--
--
-- iterM f = mapM (\a -> f a >>= \() -> return a)
--
--
-- Since 0.5.6
iterM :: Monad m => (a -> m ()) -> Conduit a m a
-- | Apply a monadic transformation that may fail to all values in a
-- stream, discarding the failures.
--
-- Since 0.5.1
mapMaybeM :: Monad m => (a -> m (Maybe b)) -> Conduit a m b
-- | Apply a monadic transformation to all values in a stream,
-- concatenating the output values.
--
-- Since 0.3.0
concatMapM :: Monad m => (a -> m [b]) -> Conduit a m b
-- | concatMapM with an accumulator.
--
-- Since 0.3.0
concatMapAccumM :: Monad m => (a -> accum -> m (accum, [b])) -> accum -> Conduit a m b
-- | Run a Pipe repeatedly, and output its result value
-- downstream. Stops when no more input is available from upstream.
--
-- Since 0.5.0
sequence :: Monad m => Consumer i m o -> Conduit i m o
-- | Functions for interacting with bytes.
module Data.Conduit.Binary
-- | Stream the contents of a file as binary data.
--
-- Since 0.3.0
sourceFile :: MonadResource m => FilePath -> Producer m ByteString
-- | Stream the contents of a Handle as binary data. Note that this
-- function will not automatically close the Handle when
-- processing completes, since it did not acquire the Handle in
-- the first place.
--
-- Since 0.3.0
sourceHandle :: MonadIO m => Handle -> Producer m ByteString
-- | An alternative to sourceHandle. Instead of taking a pre-opened
-- Handle, it takes an action that opens a Handle (in read
-- mode), so that it can open it only when needed and closed it as soon
-- as possible.
--
-- Since 0.3.0
sourceIOHandle :: MonadResource m => IO Handle -> Producer m ByteString
-- | Stream the contents of a file as binary data, starting from a certain
-- offset and only consuming up to a certain number of bytes.
--
-- Since 0.3.0
sourceFileRange :: MonadResource m => FilePath -> Maybe Integer -> Maybe Integer -> Producer m ByteString
-- | Stream all incoming data to the given file.
--
-- Since 0.3.0
sinkFile :: MonadResource m => FilePath -> Consumer ByteString m ()
-- | Stream all incoming data to the given Handle. Note that this
-- function will not automatically close the Handle when
-- processing completes.
--
-- Since 0.3.0
sinkHandle :: MonadIO m => Handle -> Consumer ByteString m ()
-- | An alternative to sinkHandle. Instead of taking a pre-opened
-- Handle, it takes an action that opens a Handle (in write
-- mode), so that it can open it only when needed and close it as soon as
-- possible.
--
-- Since 0.3.0
sinkIOHandle :: MonadResource m => IO Handle -> Consumer ByteString m ()
-- | Stream the contents of the input to a file, and also send it along the
-- pipeline. Similar in concept to the Unix command tee.
--
-- Since 0.3.0
conduitFile :: MonadResource m => FilePath -> Conduit ByteString m ByteString
-- | Stream the chunks from a lazy bytestring.
--
-- Since 0.5.0
sourceLbs :: Monad m => ByteString -> Producer m ByteString
-- | Return the next byte from the stream, if available.
--
-- Since 0.3.0
head :: Monad m => Consumer ByteString m (Maybe Word8)
-- | Ignore all bytes while the predicate returns True.
--
-- Since 0.3.0
dropWhile :: Monad m => (Word8 -> Bool) -> Consumer ByteString m ()
-- | Take the given number of bytes, if available.
--
-- Since 0.3.0
take :: Monad m => Int -> Consumer ByteString m ByteString
-- | Drop up to the given number of bytes.
--
-- Since 0.5.0
drop :: Monad m => Int -> Consumer ByteString m ()
-- | Ensure that only up to the given number of bytes are consume by the
-- inner sink. Note that this does not ensure that all of those
-- bytes are in fact consumed.
--
-- Since 0.3.0
isolate :: Monad m => Int -> Conduit ByteString m ByteString
-- | Return all bytes while the predicate returns True.
--
-- Since 0.3.0
takeWhile :: Monad m => (Word8 -> Bool) -> Conduit ByteString m ByteString
-- | Split the input bytes into lines. In other words, split on the LF byte
-- (10), and strip it from the output.
--
-- Since 0.3.0
lines :: Monad m => Conduit ByteString m ByteString
-- | Handle streams of text.
--
-- Parts of this code were taken from enumerator and adapted for
-- conduits.
module Data.Conduit.Text
-- | A specific character encoding.
--
-- Since 0.3.0
data Codec
-- | Convert text into bytes, using the provided codec. If the codec is not
-- capable of representing an input character, an exception will be
-- thrown.
--
-- Since 0.3.0
encode :: MonadThrow m => Codec -> Conduit Text m ByteString
-- | Convert bytes into text, using the provided codec. If the codec is not
-- capable of decoding an input byte sequence, an exception will be
-- thrown.
--
-- Since 0.3.0
decode :: MonadThrow m => Codec -> Conduit ByteString m Text
-- | Since 0.3.0
utf8 :: Codec
-- | Since 0.3.0
utf16_le :: Codec
-- | Since 0.3.0
utf16_be :: Codec
-- | Since 0.3.0
utf32_le :: Codec
-- | Since 0.3.0
utf32_be :: Codec
-- | Since 0.3.0
ascii :: Codec
-- | Since 0.3.0
iso8859_1 :: Codec
-- | Emit each line separately
--
-- Since 0.4.1
lines :: Monad m => Conduit Text m Text
-- | Variant of the lines function with an integer parameter. The text
-- length of any emitted line never exceeds the value of the paramater.
-- Whenever this is about to happen a LengthExceeded exception is thrown.
-- This function should be used instead of the lines function whenever we
-- are dealing with user input (e.g. a file upload) because we can't be
-- sure that user input won't have extraordinarily large lines which
-- would require large amounts of memory if consumed.
linesBounded :: MonadThrow m => Int -> Conduit Text m Text
-- | Since 0.3.0
data TextException
DecodeException :: Codec -> Word8 -> TextException
EncodeException :: Codec -> Char -> TextException
LengthExceeded :: Int -> TextException
TextException :: SomeException -> TextException
instance Typeable TextException
instance Show TextException
instance Exception TextException
instance Show Codec
-- | Use lazy I/O for consuming the contents of a source. Warning: All
-- normal warnings of lazy I/O apply. In particular, if you are using
-- this with a ResourceT transformer, you must force the list to
-- be evaluated before exiting the ResourceT.
module Data.Conduit.Lazy
-- | Use lazy I/O to consume all elements from a Source.
--
-- This function relies on monadActive to determine if the
-- underlying monadic state has been closed.
--
-- Since 0.3.0
lazyConsume :: (MonadBaseControl IO m, MonadActive m) => Source m a -> m [a]