-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Streaming data processing library. -- -- Conduits are an approach to the streaming data problem. It is meant as -- an alternative to enumerators/iterators, hoping to address the same -- issues with different trade-offs based on real-world experience with -- enumerators. For more information, see -- http://www.yesodweb.com/book/conduit. -- -- Release history: -- -- @package conduit @version 0.2.1 -- | Allocate resources which are guaranteed to be released. -- -- For more information, see -- http://www.yesodweb.com/blog/2011/12/resourcet. -- -- One point to note: all register cleanup actions live in the base -- monad, not the main monad. This allows both more efficient code, and -- for monads to be transformed. module Control.Monad.Trans.Resource -- | 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 with or -- withIO. The with functions correspond 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. data ResourceT m a -- | A lookup key for a specific release action. This value is returned by -- register, with and withIO, and is passed to -- release. data ReleaseKey -- | 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. runResourceT :: Resource m => ResourceT m a -> m a -- | Perform some allocation, and automatically register a cleanup action. -- -- If you are performing an IO action, it will likely be easier -- to use the withIO function, which handles types more cleanly. with :: Resource m => Base m a -> (a -> Base m ()) -> ResourceT m (ReleaseKey, a) -- | Same as with, but explicitly uses IO as a base. withIO :: ResourceIO m => IO a -> (a -> IO ()) -> ResourceT m (ReleaseKey, a) -- | Register some action that will be called precisely once, either when -- runResourceT is called, or when the ReleaseKey is passed -- to release. register :: Resource m => Base m () -> ResourceT m ReleaseKey -- | Call a release action early, and deregister it from the list of -- cleanup actions to be performed. release :: Resource m => ReleaseKey -> ResourceT m () -- | Read a value from a reference. readRef :: Resource m => Ref (Base m) a -> ResourceT m a -- | Write a value to a reference. writeRef :: Resource m => Ref (Base m) a -> a -> ResourceT m () -- | Create a new reference. newRef :: Resource m => a -> ResourceT m (Ref (Base m) a) -- | Introduce a reference-counting scheme to allow a resource context to -- be shared by multiple threads. Once the last thread exits, all -- remaining resources will be released. -- -- Note that abuse of this function will greatly delay the deallocation -- of registered resources. This function should be used with care. A -- general guideline: -- -- If you are allocating a resource that should be shared by multiple -- threads, and will be held for a long time, you should allocate it at -- the beginning of a new ResourceT block and then call -- resourceForkIO from there. resourceForkIO :: ResourceIO m => ResourceT m () -> ResourceT m ThreadId -- | Transform the monad a ResourceT lives in. This is most often -- used to strip or add new transformers to a stack, e.g. to run a -- ReaderT. Note that the original and new monad must both have -- the same Base monad. transResourceT :: Base m ~ Base n => (m a -> n a) -> ResourceT m a -> ResourceT n a -- | The express purpose of this transformer is to allow the ST -- monad to catch exceptions via the ResourceThrow typeclass. newtype ExceptionT m a ExceptionT :: m (Either SomeException a) -> ExceptionT m a runExceptionT :: ExceptionT m a -> m (Either SomeException a) -- | Same as runExceptionT, but immediately throw any -- exception returned. runExceptionT_ :: Monad m => ExceptionT m a -> m a -- | A Monad with a base that has mutable references, and allows -- some way to run base actions and clean up properly. class (HasRef (Base m), Monad m) => Resource m where type family Base m :: * -> * resourceLiftBase :: Resource m => Base m a -> m a resourceBracket_ :: Resource m => Base m () -> Base m () -> m c -> m c -- | A Resource based on some monad which allows running of some -- IO actions, via unsafe calls. This applies to IO and -- ST, for instance. class Resource m => ResourceUnsafeIO m unsafeFromIO :: ResourceUnsafeIO m => IO a -> m a -- | A Resource which can safely run IO calls. class (ResourceBaseIO (Base m), ResourceUnsafeIO m, ResourceThrow m, MonadIO m, MonadBaseControl IO m) => ResourceIO m -- | A helper class for ResourceIO, stating that the base monad -- provides IO actions. class ResourceBaseIO m safeFromIOBase :: ResourceBaseIO m => IO a -> m a -- | A Resource which can throw exceptions. Note that this does not -- work in a vanilla ST monad. Instead, you should use the -- ExceptionT transformer on top of ST. class Resource m => ResourceThrow m resourceThrow :: (ResourceThrow m, Exception e) => e -> m a -- | A base monad which provides mutable references and some exception-safe -- way of interacting with them. For monads which cannot handle -- exceptions (e.g., ST), exceptions may be ignored. However, in -- such cases, scarce resources should not be allocated in those -- monads, as exceptions may cause the cleanup functions to not run. -- -- The instance for IO, however, is fully exception-safe. -- -- Minimal complete definition: Ref, newRef', -- readRef' and writeRef'. class Monad m => HasRef m where type family Ref m :: * -> * atomicModifyRef' sa f = do { a0 <- readRef' sa; let (a, b) = f a0; writeRef' sa a; return b } mask f = f id mask_ = mask . const try = liftM Right newRef' :: HasRef m => a -> m (Ref m a) readRef' :: HasRef m => Ref m a -> m a writeRef' :: HasRef m => Ref m a -> a -> m () atomicModifyRef' :: HasRef m => Ref m a -> (a -> (a, b)) -> m b mask :: HasRef m => ((forall a. m a -> m a) -> m b) -> m b mask_ :: HasRef m => m a -> m a try :: HasRef m => m a -> m (Either SomeException a) instance Typeable ReleaseKey instance (Monoid w, ResourceThrow m) => ResourceThrow (WriterT w m) instance ResourceThrow m => ResourceThrow (StateT s m) instance (Monoid w, ResourceThrow m) => ResourceThrow (RWST r w s m) instance (Monoid w, ResourceThrow m) => ResourceThrow (RWST r w s m) instance (Monoid w, ResourceThrow m) => ResourceThrow (WriterT w m) instance ResourceThrow m => ResourceThrow (StateT s m) instance ResourceThrow m => ResourceThrow (ReaderT r m) instance (Error e, ResourceThrow m) => ResourceThrow (ErrorT e m) instance ResourceThrow m => ResourceThrow (MaybeT m) instance ResourceThrow m => ResourceThrow (ListT m) instance ResourceThrow m => ResourceThrow (IdentityT m) instance ResourceThrow IO instance (Resource m, MonadBaseControl (Base m) m) => ResourceThrow (ExceptionT m) instance MonadBaseControl b m => MonadBaseControl b (ExceptionT m) instance MonadTransControl ExceptionT instance MonadTrans ExceptionT instance MonadBase b m => MonadBase b (ExceptionT m) instance Monad m => Monad (ExceptionT m) instance Monad m => Applicative (ExceptionT m) instance Monad m => Functor (ExceptionT m) instance MonadBaseControl b m => MonadBaseControl b (ResourceT m) instance MonadBase b m => MonadBase b (ResourceT m) instance MonadIO m => MonadIO (ResourceT m) instance MonadTrans ResourceT instance Monad m => Monad (ResourceT m) instance Monad m => Applicative (ResourceT m) instance Monad m => Functor (ResourceT m) instance Typeable1 m => Typeable1 (ResourceT m) instance (MonadTransControl t, ResourceIO m, Monad (t m), ResourceThrow (t m), MonadBaseControl IO (t m), MonadIO (t m)) => ResourceIO (t m) instance ResourceIO IO instance ResourceBaseIO IO instance (MonadTransControl t, ResourceUnsafeIO m, Monad (t m)) => ResourceUnsafeIO (t m) instance ResourceUnsafeIO (ST s) instance ResourceUnsafeIO (ST s) instance ResourceUnsafeIO IO instance (MonadTransControl t, Resource m, Monad (t m)) => Resource (t m) instance Resource (ST s) instance Resource (ST s) instance Resource IO instance HasRef (ST s) instance HasRef (ST s) instance HasRef IO -- | The main module, exporting types, utility functions, and fuse and -- connect operators. module Data.Conduit -- | Result of pulling from a source. Either a new piece of data -- (Open), or indicates that the source is now Closed. -- -- The Open constructor returns both a new value, as well as a -- new Source, which should be used in place of the previous -- Source. -- -- Since 0.2.0 data SourceResult m a Open :: (Source m a) -> a -> SourceResult m a Closed :: SourceResult m a -- | A Source has two operations on it: pull some data, and close -- the Source. Since Source is built on top of -- ResourceT, all acquired resources should be automatically -- released anyway. Closing a Source early is merely an -- optimization to free scarce resources as soon as possible. -- -- A Source is should free any resources it allocated when -- either sourceClose is called or a Closed is -- returned. However, based on the usage of ResourceT, this is -- simply an optimization. -- -- Since 0.2.0 data Source m a Source :: ResourceT m (SourceResult m a) -> ResourceT m () -> Source m a sourcePull :: Source m a -> ResourceT m (SourceResult m a) sourceClose :: Source m a -> ResourceT m () -- | When actually interacting with Sources, we sometimes want to -- be able to buffer the output, in case any intermediate steps return -- leftover data. A BufferedSource allows for such buffering. -- -- A BufferedSource, unlike a Source, is resumable, -- meaning it can be passed to multiple Sinks without -- restarting. Therefore, a BufferedSource relaxes the main -- invariant of this package: the same value may be used multiple times. -- -- The intention of a BufferedSource is to be used internally by -- an application or library, not to be part of its user-facing API. For -- example, the Warp webserver uses a BufferedSource internally -- for parsing the request headers, but then passes a normal -- Source to the web application for reading the request body. -- -- One caveat: while the types will allow you to use the buffered source -- in multiple threads, there is no guarantee that all -- BufferedSources will handle this correctly. -- -- Since 0.2.0 data BufferedSource m a -- | Places the given Source and a buffer into a mutable variable. -- Note that you should manually call bsourceClose when the -- BufferedSource is no longer in use. -- -- Since 0.2.0 bufferSource :: Resource m => Source m a -> ResourceT m (BufferedSource m a) -- | Turn a BufferedSource into a Source. Note that in -- general this will mean your original BufferedSource will be -- closed. Additionally, all leftover data from usage of the returned -- Source will be discarded. In other words: this is a -- no-going-back move. -- -- Note: bufferSource . unbufferSource is not -- the identity function. -- -- Since 0.2.0 unbufferSource :: Resource m => BufferedSource m a -> Source m a -- | Close the underlying Source for the given -- BufferedSource. Note that this function can safely be called -- multiple times, as it will first check if the Source was -- previously closed. -- -- Since 0.2.0 bsourceClose :: Resource m => BufferedSource m a -> ResourceT m () -- | A typeclass allowing us to unify operators for Source and -- BufferedSource. -- -- Since 0.2.0 class IsSource src -- | A Sink ultimately returns a single output value. Each time -- data is pushed to it, a Sink may indicate that it is still -- processing data, or that it is done, in which case it returns some -- optional leftover input and an output value. -- -- The Processing constructors provides updated push and close -- functions to be used in place of the original Sink. -- -- Since 0.2.0 data SinkResult input m output Processing :: (SinkPush input m output) -> (SinkClose m output) -> SinkResult input m output Done :: (Maybe input) -> output -> SinkResult input m output -- | In general, a sink will consume data and eventually produce an output -- when it has consumed "enough" data. There are two caveats to that -- statement: -- -- -- -- To allow for the first caveat, we have the SinkNoData -- constructor. For the second, the SinkData constructor has two -- records: one for receiving more input, and the other to indicate the -- end of a stream. Note that, at the end of a stream, some output is -- required. If a specific Sink implementation cannot always -- produce output, this should be indicated in its return value, using -- something like a Maybe or Either. -- -- A Sink should clean up any resources it has allocated when it -- returns a value, whether that be via sinkPush or -- sinkClose. -- -- Since 0.2.0 data Sink input m output SinkNoData :: output -> Sink input m output SinkData :: SinkPush input m output -> SinkClose m output -> Sink input m output sinkPush :: Sink input m output -> SinkPush input m output sinkClose :: Sink input m output -> SinkClose m output -- | This constructor is provided to allow us to create an efficient -- MonadTrans instance. SinkLift :: (ResourceT m (Sink input m output)) -> Sink input m output -- | The value of the sinkPush record. type SinkPush input m output = input -> ResourceT m (SinkResult input m output) -- | The value of the sinkClose record. type SinkClose m output = ResourceT m output -- | When data is pushed to a Conduit, it may either indicate that -- it is still producing output and provide some, or indicate that it is -- finished producing output, in which case it returns optional leftover -- input and some final output. -- -- The Producing constructor provides a new Conduit to -- be used in place of the previous one. -- -- Since 0.2.0 data ConduitResult input m output Producing :: (Conduit input m output) -> [output] -> ConduitResult input m output Finished :: (Maybe input) -> [output] -> ConduitResult input m output -- | A conduit has two operations: it can receive new input (a push), and -- can be closed. -- -- Since 0.2.0 data Conduit input m output Conduit :: ConduitPush input m output -> ConduitClose m output -> Conduit input m output conduitPush :: Conduit input m output -> ConduitPush input m output conduitClose :: Conduit input m output -> ConduitClose m output -- | The value of the conduitPush record. type ConduitPush input m output = input -> ResourceT m (ConduitResult input m output) -- | The value of the conduitClose record. type ConduitClose m output = ResourceT m [output] -- | The connect operator, which pulls data from a source and pushes to a -- sink. There are three ways this process can terminate: -- --
    --
  1. In the case of a SinkNoData constructor, the source is -- not opened at all, and the output value is returned immediately.
  2. --
  3. The sink returns Done. If the input was a -- BufferedSource, any leftover input is put in the buffer. For -- a normal Source, the leftover value is discarded, and the -- source is closed.
  4. --
  5. The source return Closed, in which case the sink is -- closed.
  6. --
-- -- Note that this function will automatically close any Sources, -- but will not close any BufferedSources, allowing them to be -- reused. -- -- Since 0.2.0 ($$) :: (IsSource src, Resource m) => src m a -> Sink a m b -> ResourceT m b -- | Left fuse, combining a source and a conduit together into a new -- source. -- -- Note that any Source passed in will be automatically closed, -- while a BufferedSource will be left open. -- -- Since 0.2.0 ($=) :: (IsSource src, Resource m) => src m a -> Conduit a m b -> Source m b -- | Right fuse, combining a conduit and a sink together into a new sink. -- -- Since 0.2.0 (=$) :: Resource m => Conduit a m b -> Sink b m c -> Sink a m c -- | Middle fuse, combining two conduits together into a new conduit. -- -- Since 0.2.0 (=$=) :: Resource m => Conduit a m b -> Conduit b m c -> Conduit a m c -- | Construct a Source with some stateful functions. This function -- addresses threading the state value for you. -- -- Since 0.2.0 sourceState :: Resource m => state -> (state -> ResourceT m (SourceStateResult state output)) -> Source m output -- | A combination of sourceIO and sourceState. -- -- Since 0.2.1 sourceStateIO :: ResourceIO m => IO state -> (state -> IO ()) -> (state -> m (SourceStateResult state output)) -> Source m output -- | The return value when pulling in the sourceState function. -- Either indicates no more data, or the next value and an updated state. -- -- Since 0.2.0 data SourceStateResult state output StateOpen :: state -> output -> SourceStateResult state output StateClosed :: SourceStateResult state output -- | Construct a Source based on some IO actions for alloc/release. -- -- Since 0.2.0 sourceIO :: ResourceIO m => IO state -> (state -> IO ()) -> (state -> m (SourceIOResult output)) -> Source m output -- | The return value when pulling in the sourceIO function. -- Either indicates no more data, or the next value. data SourceIOResult output IOOpen :: output -> SourceIOResult output IOClosed :: SourceIOResult output -- | Transform the monad a Source lives in. -- -- Note that this will not thread the individual monads together, -- meaning side effects will be lost. This function is most useful for -- transformers only providing context and not producing side-effects, -- such as ReaderT. -- -- Since 0.2.0 transSource :: (Base m ~ Base n, Monad m) => (forall a. m a -> n a) -> Source m output -> Source n output -- | Construct a Sink with some stateful functions. This function -- addresses threading the state value for you. -- -- Since 0.2.0 sinkState :: Resource m => state -> (state -> input -> ResourceT m (SinkStateResult state input output)) -> (state -> ResourceT m output) -> Sink input m output -- | A helper type for sinkState, indicating the result of being -- pushed to. It can either indicate that processing is done, or to -- continue with the updated state. -- -- Since 0.2.0 data SinkStateResult state input output StateDone :: (Maybe input) -> output -> SinkStateResult state input output StateProcessing :: state -> SinkStateResult state input output -- | Construct a Sink. Note that your push and close functions need -- not explicitly perform any cleanup. -- -- Since 0.2.0 sinkIO :: ResourceIO m => IO state -> (state -> IO ()) -> (state -> input -> m (SinkIOResult input output)) -> (state -> m output) -> Sink input m output -- | A helper type for sinkIO, indicating the result of being -- pushed to. It can either indicate that processing is done, or to -- continue. -- -- Since 0.2.0 data SinkIOResult input output IODone :: (Maybe input) -> output -> SinkIOResult input output IOProcessing :: SinkIOResult input output -- | Transform the monad a Sink lives in. -- -- See transSource for more information. -- -- Since 0.2.0 transSink :: (Base m ~ Base n, Monad m) => (forall a. m a -> n a) -> Sink input m output -> Sink input n output -- | Construct a Conduit with some stateful functions. This function -- addresses threading the state value for you. -- -- Since 0.2.0 conduitState :: Resource m => state -> (state -> input -> ResourceT m (ConduitStateResult state input output)) -> (state -> ResourceT m [output]) -> Conduit input m output -- | A helper type for conduitState, indicating the result of -- being pushed to. It can either indicate that processing is done, or to -- continue with the updated state. -- -- Since 0.2.0 data ConduitStateResult state input output StateFinished :: (Maybe input) -> [output] -> ConduitStateResult state input output StateProducing :: state -> [output] -> ConduitStateResult state input output -- | Construct a Conduit. -- -- Since 0.2.0 conduitIO :: ResourceIO m => IO state -> (state -> IO ()) -> (state -> input -> m (ConduitIOResult input output)) -> (state -> m [output]) -> Conduit input m output -- | A helper type for conduitIO, indicating the result of being -- pushed to. It can either indicate that processing is done, or to -- continue. -- -- Since 0.2.0 data ConduitIOResult input output IOFinished :: (Maybe input) -> [output] -> ConduitIOResult input output IOProducing :: [output] -> ConduitIOResult input output -- | Transform the monad a Conduit lives in. -- -- See transSource for more information. -- -- Since 0.2.0 transConduit :: (Monad m, Base m ~ Base n) => (forall a. m a -> n a) -> Conduit input m output -> Conduit input n output -- | Helper type for constructing a Conduit based on -- Sinks. This allows you to write higher-level code that takes -- advantage of existing conduits and sinks, and leverages a sink's -- monadic interface. -- -- Since 0.2.0 type SequencedSink state input m output = state -> Sink input m (SequencedSinkResponse state input m output) -- | Convert a SequencedSink into a Conduit. -- -- Since 0.2.0 sequenceSink :: Resource m => state -> SequencedSink state input m output -> Conduit input m output -- | Specialised version of sequenceSink -- -- Note that this function will return an infinite stream if provided a -- SinkNoData constructor. In other words, you probably don't -- want to do sequence . return. -- -- Since 0.2.1 sequence :: Resource m => Sink input m output -> Conduit input m output -- | Return value from a SequencedSink. -- -- Since 0.2.0 data SequencedSinkResponse state input m output -- | Set a new state, and emit some new output. Emit :: state -> [output] -> SequencedSinkResponse state input m output -- | End the conduit. Stop :: SequencedSinkResponse state input m output -- | Pass control to a new conduit. StartConduit :: (Conduit input m output) -> SequencedSinkResponse state input m output -- | 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.2.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 with or -- withIO. The with functions correspond 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. data ResourceT m a -- | A Monad with a base that has mutable references, and allows -- some way to run base actions and clean up properly. class (HasRef (Base m), Monad m) => Resource m where type family Base m :: * -> * resourceLiftBase :: Resource m => Base m a -> m a resourceBracket_ :: Resource m => Base m () -> Base m () -> m c -> m c -- | A Resource which can safely run IO calls. class (ResourceBaseIO (Base m), ResourceUnsafeIO m, ResourceThrow m, MonadIO m, MonadBaseControl IO m) => ResourceIO m -- | A Resource based on some monad which allows running of some -- IO actions, via unsafe calls. This applies to IO and -- ST, for instance. class Resource m => ResourceUnsafeIO m -- | 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. runResourceT :: Resource m => ResourceT m a -> m a -- | A Resource which can throw exceptions. Note that this does not -- work in a vanilla ST monad. Instead, you should use the -- ExceptionT transformer on top of ST. class Resource m => ResourceThrow m resourceThrow :: (ResourceThrow m, Exception e) => e -> m a instance Show a => Show (Flush a) instance Eq a => Eq (Flush a) instance Ord a => Ord (Flush a) instance Functor Flush instance IsSource BufferedSource instance IsSource Source -- | 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 -- | Convert a list into a source. -- -- Since 0.2.0 sourceList :: Resource m => [a] -> Source m a -- | A source that returns nothing. Note that this is just a -- type-restricted synonym for mempty. -- -- Since 0.2.0 sourceNull :: Resource m => Source m a -- | A strict left fold. -- -- Since 0.2.0 fold :: Resource m => (b -> a -> b) -> b -> Sink 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.2.0 take :: Resource m => Int -> Sink 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.2.0 drop :: Resource m => Int -> Sink a m () -- | Take a single value from the stream, if available. -- -- Since 0.2.0 head :: Resource m => Sink 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.2.0 peek :: Resource m => Sink 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.2.0 consume :: Resource m => Sink a m [a] -- | Ignore the remainder of values in the source. Particularly useful when -- combined with isolate. -- -- Since 0.2.0 sinkNull :: Resource m => Sink a m () -- | A monadic strict left fold. -- -- Since 0.2.0 foldM :: Resource m => (b -> a -> m b) -> b -> Sink a m b -- | Apply the action to all values in the stream. -- -- Since 0.2.0 mapM_ :: Resource m => (a -> m ()) -> Sink a m () -- | Apply a transformation to all values in a stream. -- -- Since 0.2.0 map :: Monad m => (a -> b) -> Conduit a m b -- | Apply a transformation to all values in a stream, concatenating the -- output values. -- -- Since 0.2.0 concatMap :: Monad m => (a -> [b]) -> Conduit a m b -- | concatMap with an accumulator. -- -- Since 0.2.0 concatMapAccum :: Resource m => (a -> accum -> (accum, [b])) -> accum -> Conduit a m b -- | Grouping input according to an equality function. -- -- Since 0.2.0 groupBy :: Resource 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.2.0 isolate :: Resource m => Int -> Conduit a m a -- | Keep only values in the stream passing a given predicate. -- -- Since 0.2.0 filter :: Resource 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.2.0 mapM :: Monad m => (a -> m b) -> Conduit a m b -- | Apply a monadic transformation to all values in a stream, -- concatenating the output values. -- -- Since 0.2.0 concatMapM :: Monad m => (a -> m [b]) -> Conduit a m b -- | concatMapM with an accumulator. -- -- Since 0.2.0 concatMapAccumM :: Resource m => (a -> accum -> m (accum, [b])) -> accum -> Conduit a m b -- | Functions for interacting with bytes. module Data.Conduit.Binary -- | Stream the contents of a file as binary data. -- -- Since 0.2.0 sourceFile :: ResourceIO m => FilePath -> Source 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.2.0 sourceHandle :: ResourceIO m => Handle -> Source 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 close it as soon as -- possible. -- -- Since 0.2.0 sourceIOHandle :: ResourceIO m => IO Handle -> Source 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.2.0 sourceFileRange :: ResourceIO m => FilePath -> Maybe Integer -> Maybe Integer -> Source m ByteString -- | Stream all incoming data to the given file. -- -- Since 0.2.0 sinkFile :: ResourceIO m => FilePath -> Sink 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.2.0 sinkHandle :: ResourceIO m => Handle -> Sink 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.2.0 sinkIOHandle :: ResourceIO m => IO Handle -> Sink 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.2.0 conduitFile :: ResourceIO m => FilePath -> Conduit ByteString m ByteString -- | 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.2.0 isolate :: Resource m => Int -> Conduit ByteString m ByteString -- | Open a file Handle safely by automatically registering a -- release action. -- -- While you are not required to call hClose on the resulting -- handle, you should do so as early as possible to free scarce -- resources. -- -- Since 0.2.0 openFile :: ResourceIO m => FilePath -> IOMode -> ResourceT m Handle -- | Return the next byte from the stream, if available. -- -- Since 0.2.0 head :: Resource m => Sink ByteString m (Maybe Word8) -- | Return all bytes while the predicate returns True. -- -- Since 0.2.0 takeWhile :: Resource m => (Word8 -> Bool) -> Conduit ByteString m ByteString -- | Ignore all bytes while the predicate returns True. -- -- Since 0.2.0 dropWhile :: Resource m => (Word8 -> Bool) -> Sink ByteString m () -- | Take the given number of bytes, if available. -- -- Since 0.2.0 take :: Resource m => Int -> Sink 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.2.0 lines :: Resource 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.2.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.2.0 encode :: ResourceThrow 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.2.0 decode :: ResourceThrow m => Codec -> Conduit ByteString m Text -- | Since 0.2.0 utf8 :: Codec -- | Since 0.2.0 utf16_le :: Codec -- | Since 0.2.0 utf16_be :: Codec -- | Since 0.2.0 utf32_le :: Codec -- | Since 0.2.0 utf32_be :: Codec -- | Since 0.2.0 ascii :: Codec -- | Since 0.2.0 iso8859_1 :: Codec 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. However, if you consume the content -- within the ResourceT, you should be safe. module Data.Conduit.Lazy -- | Use lazy I/O to consume all elements from a Source. -- -- Since 0.2.0 lazyConsume :: MonadBaseControl IO m => Source m a -> ResourceT m [a]