-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A pull-based approach to streaming data. -- -- 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/blog/2011/12/conduits. @package conduit @version 0.0.3 -- | 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 () -- | Modify a value in a reference. Note that, in the case of IO -- stacks, this is an atomic action. modifyRef :: Resource m => Ref (Base m) a -> (a -> (a, b)) -> ResourceT m b -- | 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 :: * -> *; { modifyRef' 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 () modifyRef' :: 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. -- -- Since 0.0.0 data SourceResult a Open :: a -> SourceResult a Closed :: SourceResult a -- | A PreparedSource has two operations on it: pull some data, and -- close the PreparedSource. Since PreparedSource is built -- on top of ResourceT, all acquired resources should be -- automatically released anyway. Closing a PreparedSource early -- is merely an optimization to free scarce resources as soon as -- possible. -- -- A PreparedSource has three invariants: -- --
-- take i = isolate i =$ consume ---- -- Since 0.0.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.0.0 drop :: Resource m => Int -> Sink a m () -- | Take a single value from the stream, if available. -- -- Since 0.0.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.0.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.0.0 consume :: Resource m => Sink a m [a] -- | Ignore the remainder of values in the source. Particularly useful when -- combined with isolate. -- -- Since 0.0.0 sinkNull :: Resource m => Sink a m () -- | A monadic strict left fold. -- -- Since 0.0.0 foldM :: Resource m => (b -> a -> m b) -> b -> Sink a m b -- | Apply the action to all values in the stream. -- -- Since 0.0.0 mapM_ :: Resource m => (a -> m ()) -> Sink a m () -- | Apply a transformation to all values in a stream. -- -- Since 0.0.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.0.0 concatMap :: Monad m => (a -> [b]) -> Conduit a m b -- | Grouping input according to an equality function. -- -- Since 0.0.2 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.0.0 isolate :: Resource m => Int -> Conduit a m a -- | Keep only values in the stream passing a given predicate. -- -- Since 0.0.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.0.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.0.0 concatMapM :: Monad m => (a -> m [b]) -> Conduit a m b -- | Functions for interacting with bytes. module Data.Conduit.Binary -- | Stream the contents of a file as binary data. -- -- Since 0.0.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.0.2. sourceHandle :: ResourceIO m => 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.0.0 sourceFileRange :: ResourceIO m => FilePath -> Maybe Integer -> Maybe Integer -> Source m ByteString -- | Stream all incoming data to the given file. -- -- Since 0.0.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.0.2. sinkHandle :: ResourceIO m => 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.0.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.0.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.0.2 openFile :: ResourceIO m => FilePath -> IOMode -> ResourceT m Handle -- | Return the next byte from the stream, if available. -- -- Since 0.0.2 head :: Resource m => Sink ByteString m (Maybe Word8) -- | Return all bytes while the predicate returns True. -- -- Since 0.0.2 takeWhile :: Resource m => (Word8 -> Bool) -> Conduit ByteString m ByteString -- | Ignore all bytes while the predicate returns True. -- -- Since 0.0.2 dropWhile :: Resource m => (Word8 -> Bool) -> Sink ByteString m () -- | Take the given number of bytes, if available. -- -- Since 0.0.3 take :: Resource m => Int -> Sink 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.0.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.0.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.0.0 decode :: ResourceThrow m => Codec -> Conduit ByteString m Text -- | Since 0.0.0 utf8 :: Codec -- | Since 0.0.0 utf16_le :: Codec -- | Since 0.0.0 utf16_be :: Codec -- | Since 0.0.0 utf32_le :: Codec -- | Since 0.0.0 utf32_be :: Codec -- | Since 0.0.0 ascii :: Codec -- | Since 0.0.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.0.0 lazyConsume :: MonadBaseControl IO m => Source m a -> ResourceT m [a]