Safe Haskell | None |
---|---|
Language | Haskell98 |
Your intended one-stop-shop for conduit functionality. This re-exports functions from many commonly used modules. When there is a conflict with standard functions, functions in this module are disambiguated by adding a trailing C (or for chunked functions, replacing a trailing E with CE). This means that the Conduit module can be imported unqualified without causing naming conflicts.
For more information on the naming scheme and intended usages of the combinators, please see the Data.Conduit.Combinators documentation.
Synopsis
- module Data.Conduit
- module Data.Conduit.Lift
- yieldMany :: (Monad m, MonoFoldable mono) => mono -> ConduitT i (Element mono) m ()
- unfoldC :: Monad m => (b -> Maybe (a, b)) -> b -> ConduitT i a m ()
- enumFromToC :: (Monad m, Enum a, Ord a) => a -> a -> ConduitT i a m ()
- iterateC :: Monad m => (a -> a) -> a -> ConduitT i a m ()
- repeatC :: Monad m => a -> ConduitT i a m ()
- replicateC :: Monad m => Int -> a -> ConduitT i a m ()
- sourceLazy :: (Monad m, LazySequence lazy strict) => lazy -> ConduitT i strict m ()
- repeatMC :: Monad m => m a -> ConduitT i a m ()
- repeatWhileMC :: Monad m => m a -> (a -> Bool) -> ConduitT i a m ()
- replicateMC :: Monad m => Int -> m a -> ConduitT i a m ()
- sourceFile :: MonadResource m => FilePath -> ConduitT i ByteString m ()
- sourceFileBS :: MonadResource m => FilePath -> ConduitT i ByteString m ()
- sourceHandle :: MonadIO m => Handle -> ConduitT i ByteString m ()
- sourceHandleUnsafe :: MonadIO m => Handle -> ConduitT i ByteString m ()
- sourceIOHandle :: MonadResource m => IO Handle -> ConduitT i ByteString m ()
- stdinC :: MonadIO m => ConduitT i ByteString m ()
- withSourceFile :: (MonadUnliftIO m, MonadIO n) => FilePath -> (ConduitM i ByteString n () -> m a) -> m a
- sourceDirectory :: MonadResource m => FilePath -> ConduitT i FilePath m ()
- sourceDirectoryDeep :: MonadResource m => Bool -> FilePath -> ConduitT i FilePath m ()
- dropC :: Monad m => Int -> ConduitT a o m ()
- dropCE :: (Monad m, IsSequence seq) => Index seq -> ConduitT seq o m ()
- dropWhileC :: Monad m => (a -> Bool) -> ConduitT a o m ()
- dropWhileCE :: (Monad m, IsSequence seq) => (Element seq -> Bool) -> ConduitT seq o m ()
- foldC :: (Monad m, Monoid a) => ConduitT a o m a
- foldCE :: (Monad m, MonoFoldable mono, Monoid (Element mono)) => ConduitT mono o m (Element mono)
- foldlC :: Monad m => (a -> b -> a) -> a -> ConduitT b o m a
- foldlCE :: (Monad m, MonoFoldable mono) => (a -> Element mono -> a) -> a -> ConduitT mono o m a
- foldMapC :: (Monad m, Monoid b) => (a -> b) -> ConduitT a o m b
- foldMapCE :: (Monad m, MonoFoldable mono, Monoid w) => (Element mono -> w) -> ConduitT mono o m w
- allC :: Monad m => (a -> Bool) -> ConduitT a o m Bool
- allCE :: (Monad m, MonoFoldable mono) => (Element mono -> Bool) -> ConduitT mono o m Bool
- anyC :: Monad m => (a -> Bool) -> ConduitT a o m Bool
- anyCE :: (Monad m, MonoFoldable mono) => (Element mono -> Bool) -> ConduitT mono o m Bool
- andC :: Monad m => ConduitT Bool o m Bool
- andCE :: (Monad m, MonoFoldable mono, Element mono ~ Bool) => ConduitT mono o m Bool
- orC :: Monad m => ConduitT Bool o m Bool
- orCE :: (Monad m, MonoFoldable mono, Element mono ~ Bool) => ConduitT mono o m Bool
- asumC :: (Monad m, Alternative f) => ConduitT (f a) o m (f a)
- elemC :: (Monad m, Eq a) => a -> ConduitT a o m Bool
- elemCE :: (Monad m, IsSequence seq, Eq (Element seq)) => Element seq -> ConduitT seq o m Bool
- notElemC :: (Monad m, Eq a) => a -> ConduitT a o m Bool
- notElemCE :: (Monad m, IsSequence seq, Eq (Element seq)) => Element seq -> ConduitT seq o m Bool
- sinkLazy :: (Monad m, LazySequence lazy strict) => ConduitT strict o m lazy
- sinkList :: Monad m => ConduitT a o m [a]
- sinkVector :: (Vector v a, PrimMonad m) => ConduitT a o m (v a)
- sinkVectorN :: (Vector v a, PrimMonad m) => Int -> ConduitT a o m (v a)
- sinkLazyBuilder :: Monad m => ConduitT Builder o m ByteString
- sinkNull :: Monad m => ConduitT a o m ()
- awaitNonNull :: (Monad m, MonoFoldable a) => ConduitT a o m (Maybe (NonNull a))
- headC :: Monad m => ConduitT a o m (Maybe a)
- headDefC :: Monad m => a -> ConduitT a o m a
- headCE :: (Monad m, IsSequence seq) => ConduitT seq o m (Maybe (Element seq))
- peekC :: Monad m => ConduitT a o m (Maybe a)
- peekCE :: (Monad m, MonoFoldable mono) => ConduitT mono o m (Maybe (Element mono))
- lastC :: Monad m => ConduitT a o m (Maybe a)
- lastDefC :: Monad m => a -> ConduitT a o m a
- lastCE :: (Monad m, IsSequence seq) => ConduitT seq o m (Maybe (Element seq))
- lengthC :: (Monad m, Num len) => ConduitT a o m len
- lengthCE :: (Monad m, Num len, MonoFoldable mono) => ConduitT mono o m len
- lengthIfC :: (Monad m, Num len) => (a -> Bool) -> ConduitT a o m len
- lengthIfCE :: (Monad m, Num len, MonoFoldable mono) => (Element mono -> Bool) -> ConduitT mono o m len
- maximumC :: (Monad m, Ord a) => ConduitT a o m (Maybe a)
- maximumCE :: (Monad m, IsSequence seq, Ord (Element seq)) => ConduitT seq o m (Maybe (Element seq))
- minimumC :: (Monad m, Ord a) => ConduitT a o m (Maybe a)
- minimumCE :: (Monad m, IsSequence seq, Ord (Element seq)) => ConduitT seq o m (Maybe (Element seq))
- nullC :: Monad m => ConduitT a o m Bool
- nullCE :: (Monad m, MonoFoldable mono) => ConduitT mono o m Bool
- sumC :: (Monad m, Num a) => ConduitT a o m a
- sumCE :: (Monad m, MonoFoldable mono, Num (Element mono)) => ConduitT mono o m (Element mono)
- productC :: (Monad m, Num a) => ConduitT a o m a
- productCE :: (Monad m, MonoFoldable mono, Num (Element mono)) => ConduitT mono o m (Element mono)
- findC :: Monad m => (a -> Bool) -> ConduitT a o m (Maybe a)
- mapM_C :: Monad m => (a -> m ()) -> ConduitT a o m ()
- mapM_CE :: (Monad m, MonoFoldable mono) => (Element mono -> m ()) -> ConduitT mono o m ()
- foldMC :: Monad m => (a -> b -> m a) -> a -> ConduitT b o m a
- foldMCE :: (Monad m, MonoFoldable mono) => (a -> Element mono -> m a) -> a -> ConduitT mono o m a
- foldMapMC :: (Monad m, Monoid w) => (a -> m w) -> ConduitT a o m w
- foldMapMCE :: (Monad m, MonoFoldable mono, Monoid w) => (Element mono -> m w) -> ConduitT mono o m w
- sinkFile :: MonadResource m => FilePath -> ConduitT ByteString o m ()
- sinkFileCautious :: MonadResource m => FilePath -> ConduitM ByteString o m ()
- sinkTempFile :: MonadResource m => FilePath -> String -> ConduitM ByteString o m FilePath
- sinkSystemTempFile :: MonadResource m => String -> ConduitM ByteString o m FilePath
- sinkFileBS :: MonadResource m => FilePath -> ConduitT ByteString o m ()
- sinkHandle :: MonadIO m => Handle -> ConduitT ByteString o m ()
- sinkIOHandle :: MonadResource m => IO Handle -> ConduitT ByteString o m ()
- printC :: (Show a, MonadIO m) => ConduitT a o m ()
- stdoutC :: MonadIO m => ConduitT ByteString o m ()
- stderrC :: MonadIO m => ConduitT ByteString o m ()
- withSinkFile :: (MonadUnliftIO m, MonadIO n) => FilePath -> (ConduitM ByteString o n () -> m a) -> m a
- withSinkFileBuilder :: (MonadUnliftIO m, MonadIO n) => FilePath -> (ConduitM Builder o n () -> m a) -> m a
- withSinkFileCautious :: (MonadUnliftIO m, MonadIO n) => FilePath -> (ConduitM ByteString o n () -> m a) -> m a
- sinkHandleBuilder :: MonadIO m => Handle -> ConduitM Builder o m ()
- sinkHandleFlush :: MonadIO m => Handle -> ConduitM (Flush ByteString) o m ()
- mapC :: Monad m => (a -> b) -> ConduitT a b m ()
- mapCE :: (Monad m, Functor f) => (a -> b) -> ConduitT (f a) (f b) m ()
- omapCE :: (Monad m, MonoFunctor mono) => (Element mono -> Element mono) -> ConduitT mono mono m ()
- concatMapC :: (Monad m, MonoFoldable mono) => (a -> mono) -> ConduitT a (Element mono) m ()
- concatMapCE :: (Monad m, MonoFoldable mono, Monoid w) => (Element mono -> w) -> ConduitT mono w m ()
- takeC :: Monad m => Int -> ConduitT a a m ()
- takeCE :: (Monad m, IsSequence seq) => Index seq -> ConduitT seq seq m ()
- takeWhileC :: Monad m => (a -> Bool) -> ConduitT a a m ()
- takeWhileCE :: (Monad m, IsSequence seq) => (Element seq -> Bool) -> ConduitT seq seq m ()
- takeExactlyC :: Monad m => Int -> ConduitT a b m r -> ConduitT a b m r
- takeExactlyCE :: (Monad m, IsSequence a) => Index a -> ConduitT a b m r -> ConduitT a b m r
- concatC :: (Monad m, MonoFoldable mono) => ConduitT mono (Element mono) m ()
- filterC :: Monad m => (a -> Bool) -> ConduitT a a m ()
- filterCE :: (IsSequence seq, Monad m) => (Element seq -> Bool) -> ConduitT seq seq m ()
- mapWhileC :: Monad m => (a -> Maybe b) -> ConduitT a b m ()
- conduitVector :: (Vector v a, PrimMonad m) => Int -> ConduitT a (v a) m ()
- scanlC :: Monad m => (a -> b -> a) -> a -> ConduitT b a m ()
- mapAccumWhileC :: Monad m => (a -> s -> Either s (s, b)) -> s -> ConduitT a b m s
- concatMapAccumC :: Monad m => (a -> accum -> (accum, [b])) -> accum -> ConduitT a b m ()
- intersperseC :: Monad m => a -> ConduitT a a m ()
- slidingWindowC :: (Monad m, IsSequence seq, Element seq ~ a) => Int -> ConduitT a seq m ()
- chunksOfCE :: (Monad m, IsSequence seq) => Index seq -> ConduitT seq seq m ()
- chunksOfExactlyCE :: (Monad m, IsSequence seq) => Index seq -> ConduitT seq seq m ()
- mapMC :: Monad m => (a -> m b) -> ConduitT a b m ()
- mapMCE :: (Monad m, Traversable f) => (a -> m b) -> ConduitT (f a) (f b) m ()
- omapMCE :: (Monad m, MonoTraversable mono) => (Element mono -> m (Element mono)) -> ConduitT mono mono m ()
- concatMapMC :: (Monad m, MonoFoldable mono) => (a -> m mono) -> ConduitT a (Element mono) m ()
- filterMC :: Monad m => (a -> m Bool) -> ConduitT a a m ()
- filterMCE :: (Monad m, IsSequence seq) => (Element seq -> m Bool) -> ConduitT seq seq m ()
- iterMC :: Monad m => (a -> m ()) -> ConduitT a a m ()
- scanlMC :: Monad m => (a -> b -> m a) -> a -> ConduitT b a m ()
- mapAccumWhileMC :: Monad m => (a -> s -> m (Either s (s, b))) -> s -> ConduitT a b m s
- concatMapAccumMC :: Monad m => (a -> accum -> m (accum, [b])) -> accum -> ConduitT a b m ()
- encodeUtf8C :: (Monad m, Utf8 text binary) => ConduitT text binary m ()
- decodeUtf8C :: MonadThrow m => ConduitT ByteString Text m ()
- decodeUtf8LenientC :: Monad m => ConduitT ByteString Text m ()
- lineC :: (Monad m, IsSequence seq, Element seq ~ Char) => ConduitT seq o m r -> ConduitT seq o m r
- lineAsciiC :: (Monad m, IsSequence seq, Element seq ~ Word8) => ConduitT seq o m r -> ConduitT seq o m r
- unlinesC :: (Monad m, IsSequence seq, Element seq ~ Char) => ConduitT seq seq m ()
- unlinesAsciiC :: (Monad m, IsSequence seq, Element seq ~ Word8) => ConduitT seq seq m ()
- linesUnboundedC :: (Monad m, IsSequence seq, Element seq ~ Char) => ConduitT seq seq m ()
- linesUnboundedAsciiC :: (Monad m, IsSequence seq, Element seq ~ Word8) => ConduitT seq seq m ()
- builderToByteString :: PrimMonad m => ConduitT Builder ByteString m ()
- unsafeBuilderToByteString :: PrimMonad m => ConduitT Builder ByteString m ()
- builderToByteStringWith :: PrimMonad m => BufferAllocStrategy -> ConduitT Builder ByteString m ()
- builderToByteStringFlush :: PrimMonad m => ConduitT (Flush Builder) (Flush ByteString) m ()
- builderToByteStringWithFlush :: PrimMonad m => BufferAllocStrategy -> ConduitT (Flush Builder) (Flush ByteString) m ()
- type BufferAllocStrategy = (IO Buffer, Int -> Buffer -> IO (IO Buffer))
- allNewBuffersStrategy :: Int -> BufferAllocStrategy
- reuseBufferStrategy :: IO Buffer -> BufferAllocStrategy
- vectorBuilderC :: (PrimMonad m, Vector v e, PrimMonad n, PrimState m ~ PrimState n) => Int -> ((e -> n ()) -> ConduitT i Void m r) -> ConduitT i (v e) m r
- mapAccumS :: Monad m => (a -> s -> ConduitT b Void m s) -> s -> ConduitT () b m () -> ConduitT a Void m s
- peekForever :: Monad m => ConduitT i o m () -> ConduitT i o m ()
- peekForeverE :: (Monad m, MonoFoldable i) => ConduitT i o m () -> ConduitT i o m ()
- class Monad m => MonadIO (m :: * -> *) where
- class MonadTrans (t :: (* -> *) -> * -> *) where
- class Monad m => MonadThrow (m :: * -> *) where
- class MonadIO m => MonadUnliftIO (m :: * -> *) where
- class Monad m => PrimMonad (m :: * -> *) where
- class MonadIO m => MonadResource (m :: * -> *)
- data ResourceT (m :: * -> *) a
- runResourceT :: MonadUnliftIO m => ResourceT m a -> m a
- withAcquire :: MonadUnliftIO m => Acquire a -> (a -> m b) -> m b
- allocateAcquire :: MonadResource m => Acquire a -> m (ReleaseKey, a)
- mkAcquireType :: IO a -> (a -> ReleaseType -> IO ()) -> Acquire a
- mkAcquire :: IO a -> (a -> IO ()) -> Acquire a
- data ReleaseType
- data Acquire a
- newtype Identity a = Identity {
- runIdentity :: a
Core conduit library
module Data.Conduit
module Data.Conduit.Lift
Commonly used combinators
Producers
Pure
yieldMany :: (Monad m, MonoFoldable mono) => mono -> ConduitT i (Element mono) m () Source #
Yield each of the values contained by the given MonoFoldable
.
This will work on many data structures, including lists, ByteString
s, and Vector
s.
Subject to fusion
Since: conduit-1.3.0
unfoldC :: Monad m => (b -> Maybe (a, b)) -> b -> ConduitT i a m () Source #
Generate a producer from a seed value.
Since: conduit-1.3.0
enumFromToC :: (Monad m, Enum a, Ord a) => a -> a -> ConduitT i a m () Source #
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: conduit-1.3.0
iterateC :: Monad m => (a -> a) -> a -> ConduitT i a m () Source #
Produces an infinite stream of repeated applications of f to x.
Since: conduit-1.3.0
repeatC :: Monad m => a -> ConduitT i a m () Source #
Produce an infinite stream consisting entirely of the given value.
Since: conduit-1.3.0
replicateC :: Monad m => Int -> a -> ConduitT i a m () Source #
Produce a finite stream consisting of n copies of the given value.
Since: conduit-1.3.0
sourceLazy :: (Monad m, LazySequence lazy strict) => lazy -> ConduitT i strict m () Source #
Generate a producer by yielding each of the strict chunks in a LazySequence
.
For more information, see toChunks
.
Subject to fusion
Since: conduit-1.3.0
Monadic
repeatMC :: Monad m => m a -> ConduitT i a m () Source #
Repeatedly run the given action and yield all values it produces.
Since: conduit-1.3.0
repeatWhileMC :: Monad m => m a -> (a -> Bool) -> ConduitT i a m () Source #
Repeatedly run the given action and yield all values it produces, until
the provided predicate returns False
.
Since: conduit-1.3.0
replicateMC :: Monad m => Int -> m a -> ConduitT i a m () Source #
Perform the given action n times, yielding each result.
Since: conduit-1.3.0
I/O
sourceFile :: MonadResource m => FilePath -> ConduitT i ByteString m () Source #
Stream the contents of a file as binary data.
Since: conduit-1.3.0
sourceFileBS :: MonadResource m => FilePath -> ConduitT i ByteString m () Source #
Same as sourceFile
. The alternate name is a holdover from an older
version, when sourceFile
was more polymorphic than it is today.
Since: conduit-1.3.0
sourceHandle :: MonadIO m => Handle -> ConduitT i ByteString m () Source #
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: conduit-1.3.0
sourceHandleUnsafe :: MonadIO m => Handle -> ConduitT i ByteString m () Source #
Same as sourceHandle
, but instead of allocating a new buffer for each
incoming chunk of data, reuses the same buffer. Therefore, the ByteString
s
yielded by this function are not referentially transparent between two
different yield
s.
This function will be slightly more efficient than sourceHandle
by
avoiding allocations and reducing garbage collections, but should only be
used if you can guarantee that you do not reuse a ByteString
(or any slice
thereof) between two calls to await
.
Since: conduit-1.3.0
sourceIOHandle :: MonadResource m => IO Handle -> ConduitT i ByteString m () Source #
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: conduit-1.3.0
stdinC :: MonadIO m => ConduitT i ByteString m () Source #
sourceHandle
applied to stdin
.
Since: conduit-1.3.0
withSourceFile :: (MonadUnliftIO m, MonadIO n) => FilePath -> (ConduitM i ByteString n () -> m a) -> m a Source #
Like withBinaryFile
, but provides a source to read bytes from.
Since: conduit-1.3.0
Filesystem
sourceDirectory :: MonadResource m => FilePath -> ConduitT i FilePath m () Source #
Stream the contents of the given directory, without traversing deeply.
This function will return all of the contents of the directory, whether they be files, directories, etc.
Note that the generated filepaths will be the complete path, not just the
filename. In other words, if you have a directory foo
containing files
bar
and baz
, and you use sourceDirectory
on foo
, the results will be
foo/bar
and foo/baz
.
Since: conduit-1.3.0
:: MonadResource m | |
=> Bool | Follow directory symlinks |
-> FilePath | Root directory |
-> ConduitT i FilePath m () |
Deeply stream the contents of the given directory.
This works the same as sourceDirectory
, but will not return directories at
all. This function also takes an extra parameter to indicate whether
symlinks will be followed.
Since: conduit-1.3.0
Consumers
Pure
dropC :: Monad m => Int -> ConduitT a o m () Source #
Ignore a certain number of values in the stream.
Note: since this function doesn't produce anything, you probably want to
use it with (>>
) instead of directly plugging it into a pipeline:
>>>
runConduit $ yieldMany [1..5] .| dropC 2 .| sinkList
[]>>>
runConduit $ yieldMany [1..5] .| (dropC 2 >> sinkList)
[3,4,5]
Since: conduit-1.3.0
dropCE :: (Monad m, IsSequence seq) => Index seq -> ConduitT seq o m () Source #
Drop a certain number of elements from a chunked stream.
Note: you likely want to use it with monadic composition. See the docs
for dropC
.
Since: conduit-1.3.0
dropWhileC :: Monad m => (a -> Bool) -> ConduitT a o m () Source #
Drop all values which match the given predicate.
Note: you likely want to use it with monadic composition. See the docs
for dropC
.
Since: conduit-1.3.0
dropWhileCE :: (Monad m, IsSequence seq) => (Element seq -> Bool) -> ConduitT seq o m () Source #
Drop all elements in the chunked stream which match the given predicate.
Note: you likely want to use it with monadic composition. See the docs
for dropC
.
Since: conduit-1.3.0
foldC :: (Monad m, Monoid a) => ConduitT a o m a Source #
Monoidally combine all values in the stream.
Since: conduit-1.3.0
foldCE :: (Monad m, MonoFoldable mono, Monoid (Element mono)) => ConduitT mono o m (Element mono) Source #
Monoidally combine all elements in the chunked stream.
Since: conduit-1.3.0
foldlC :: Monad m => (a -> b -> a) -> a -> ConduitT b o m a Source #
A strict left fold.
Since: conduit-1.3.0
foldlCE :: (Monad m, MonoFoldable mono) => (a -> Element mono -> a) -> a -> ConduitT mono o m a Source #
A strict left fold on a chunked stream.
Since: conduit-1.3.0
foldMapC :: (Monad m, Monoid b) => (a -> b) -> ConduitT a o m b Source #
Apply the provided mapping function and monoidal combine all values.
Since: conduit-1.3.0
foldMapCE :: (Monad m, MonoFoldable mono, Monoid w) => (Element mono -> w) -> ConduitT mono o m w Source #
Apply the provided mapping function and monoidal combine all elements of the chunked stream.
Since: conduit-1.3.0
allC :: Monad m => (a -> Bool) -> ConduitT a o m Bool Source #
Check that all values in the stream return True.
Subject to shortcut logic: at the first False, consumption of the stream will stop.
Since: conduit-1.3.0
allCE :: (Monad m, MonoFoldable mono) => (Element mono -> Bool) -> ConduitT mono o m Bool Source #
Check that all elements in the chunked stream return True.
Subject to shortcut logic: at the first False, consumption of the stream will stop.
Since: conduit-1.3.0
anyC :: Monad m => (a -> Bool) -> ConduitT a o m Bool Source #
Check that at least one value in the stream returns True.
Subject to shortcut logic: at the first True, consumption of the stream will stop.
Since: conduit-1.3.0
anyCE :: (Monad m, MonoFoldable mono) => (Element mono -> Bool) -> ConduitT mono o m Bool Source #
Check that at least one element in the chunked stream returns True.
Subject to shortcut logic: at the first True, consumption of the stream will stop.
Since: conduit-1.3.0
andC :: Monad m => ConduitT Bool o m Bool Source #
Are all values in the stream True?
Consumption stops once the first False is encountered.
Since: conduit-1.3.0
andCE :: (Monad m, MonoFoldable mono, Element mono ~ Bool) => ConduitT mono o m Bool Source #
Are all elements in the chunked stream True?
Consumption stops once the first False is encountered.
Since: conduit-1.3.0
orC :: Monad m => ConduitT Bool o m Bool Source #
Are any values in the stream True?
Consumption stops once the first True is encountered.
Since: conduit-1.3.0
orCE :: (Monad m, MonoFoldable mono, Element mono ~ Bool) => ConduitT mono o m Bool Source #
Are any elements in the chunked stream True?
Consumption stops once the first True is encountered.
Since: conduit-1.3.0
asumC :: (Monad m, Alternative f) => ConduitT (f a) o m (f a) Source #
Alternative
ly combine all values in the stream.
Since: conduit-1.3.0
elemC :: (Monad m, Eq a) => a -> ConduitT a o m Bool Source #
Are any values in the stream equal to the given value?
Stops consuming as soon as a match is found.
Since: conduit-1.3.0
elemCE :: (Monad m, IsSequence seq, Eq (Element seq)) => Element seq -> ConduitT seq o m Bool Source #
Are any elements in the chunked stream equal to the given element?
Stops consuming as soon as a match is found.
Since: conduit-1.3.0
notElemC :: (Monad m, Eq a) => a -> ConduitT a o m Bool Source #
Are no values in the stream equal to the given value?
Stops consuming as soon as a match is found.
Since: conduit-1.3.0
notElemCE :: (Monad m, IsSequence seq, Eq (Element seq)) => Element seq -> ConduitT seq o m Bool Source #
Are no elements in the chunked stream equal to the given element?
Stops consuming as soon as a match is found.
Since: conduit-1.3.0
sinkLazy :: (Monad m, LazySequence lazy strict) => ConduitT strict o m lazy Source #
Consume all incoming strict chunks into a lazy sequence. Note that the entirety of the sequence will be resident at memory.
This can be used to consume a stream of strict ByteStrings into a lazy ByteString, for example.
Subject to fusion
Since: conduit-1.3.0
sinkList :: Monad m => ConduitT a o m [a] Source #
Consume all values from the stream and return as a list. Note that this will pull all values into memory.
Subject to fusion
Since: conduit-1.3.0
sinkVector :: (Vector v a, PrimMonad m) => ConduitT a o m (v a) Source #
Sink incoming values into a vector, growing the vector as necessary to fit more elements.
Note that using this function is more memory efficient than sinkList
and
then converting to a Vector
, as it avoids intermediate list constructors.
Subject to fusion
Since: conduit-1.3.0
Sink incoming values into a vector, up until size maxSize
. Subsequent
values will be left in the stream. If there are less than maxSize
values
present, returns a Vector
of smaller size.
Note that using this function is more memory efficient than sinkList
and
then converting to a Vector
, as it avoids intermediate list constructors.
Subject to fusion
Since: conduit-1.3.0
sinkLazyBuilder :: Monad m => ConduitT Builder o m ByteString Source #
Same as sinkBuilder
, but afterwards convert the builder to its lazy
representation.
Alternatively, this could be considered an alternative to sinkLazy
, with
the following differences:
- This function will allow multiple input types, not just the strict version of the lazy structure.
- Some buffer copying may occur in this version.
Subject to fusion
Since: conduit-1.3.0
sinkNull :: Monad m => ConduitT a o m () Source #
Consume and discard all remaining values in the stream.
Subject to fusion
Since: conduit-1.3.0
awaitNonNull :: (Monad m, MonoFoldable a) => ConduitT a o m (Maybe (NonNull a)) Source #
Same as await
, but discards any leading onull
values.
Since: conduit-1.3.0
headC :: Monad m => ConduitT a o m (Maybe a) Source #
Take a single value from the stream, if available.
Since: conduit-1.3.0
headDefC :: Monad m => a -> ConduitT a o m a Source #
Same as headC
, but returns a default value if none are available from the stream.
Since: conduit-1.3.0
headCE :: (Monad m, IsSequence seq) => ConduitT seq o m (Maybe (Element seq)) Source #
Get the next element in the chunked stream.
Since: conduit-1.3.0
peekC :: Monad m => ConduitT a o m (Maybe a) Source #
View the next value in the stream without consuming it.
Since: conduit-1.3.0
peekCE :: (Monad m, MonoFoldable mono) => ConduitT mono o m (Maybe (Element mono)) Source #
View the next element in the chunked stream without consuming it.
Since: conduit-1.3.0
lastC :: Monad m => ConduitT a o m (Maybe a) Source #
Retrieve the last value in the stream, if present.
Since: conduit-1.3.0
lastDefC :: Monad m => a -> ConduitT a o m a Source #
Same as lastC
, but returns a default value if none are available from the stream.
Since: conduit-1.3.0
lastCE :: (Monad m, IsSequence seq) => ConduitT seq o m (Maybe (Element seq)) Source #
Retrieve the last element in the chunked stream, if present.
Since: conduit-1.3.0
lengthC :: (Monad m, Num len) => ConduitT a o m len Source #
Count how many values are in the stream.
Since: conduit-1.3.0
lengthCE :: (Monad m, Num len, MonoFoldable mono) => ConduitT mono o m len Source #
Count how many elements are in the chunked stream.
Since: conduit-1.3.0
lengthIfC :: (Monad m, Num len) => (a -> Bool) -> ConduitT a o m len Source #
Count how many values in the stream pass the given predicate.
Since: conduit-1.3.0
lengthIfCE :: (Monad m, Num len, MonoFoldable mono) => (Element mono -> Bool) -> ConduitT mono o m len Source #
Count how many elements in the chunked stream pass the given predicate.
Since: conduit-1.3.0
maximumC :: (Monad m, Ord a) => ConduitT a o m (Maybe a) Source #
Get the largest value in the stream, if present.
Since: conduit-1.3.0
maximumCE :: (Monad m, IsSequence seq, Ord (Element seq)) => ConduitT seq o m (Maybe (Element seq)) Source #
Get the largest element in the chunked stream, if present.
Since: conduit-1.3.0
minimumC :: (Monad m, Ord a) => ConduitT a o m (Maybe a) Source #
Get the smallest value in the stream, if present.
Since: conduit-1.3.0
minimumCE :: (Monad m, IsSequence seq, Ord (Element seq)) => ConduitT seq o m (Maybe (Element seq)) Source #
Get the smallest element in the chunked stream, if present.
Since: conduit-1.3.0
nullC :: Monad m => ConduitT a o m Bool Source #
True if there are no values in the stream.
This function does not modify the stream.
Since: conduit-1.3.0
nullCE :: (Monad m, MonoFoldable mono) => ConduitT mono o m Bool Source #
True if there are no elements in the chunked stream.
This function may remove empty leading chunks from the stream, but otherwise will not modify it.
Since: conduit-1.3.0
sumC :: (Monad m, Num a) => ConduitT a o m a Source #
Get the sum of all values in the stream.
Since: conduit-1.3.0
sumCE :: (Monad m, MonoFoldable mono, Num (Element mono)) => ConduitT mono o m (Element mono) Source #
Get the sum of all elements in the chunked stream.
Since: conduit-1.3.0
productC :: (Monad m, Num a) => ConduitT a o m a Source #
Get the product of all values in the stream.
Since: conduit-1.3.0
productCE :: (Monad m, MonoFoldable mono, Num (Element mono)) => ConduitT mono o m (Element mono) Source #
Get the product of all elements in the chunked stream.
Since: conduit-1.3.0
findC :: Monad m => (a -> Bool) -> ConduitT a o m (Maybe a) Source #
Find the first matching value.
Since: conduit-1.3.0
Monadic
mapM_C :: Monad m => (a -> m ()) -> ConduitT a o m () Source #
Apply the action to all values in the stream.
Note: if you want to pass the values instead of consuming them, use
iterM
instead.
Since: conduit-1.3.0
mapM_CE :: (Monad m, MonoFoldable mono) => (Element mono -> m ()) -> ConduitT mono o m () Source #
Apply the action to all elements in the chunked stream.
Note: the same caveat as with mapM_C
applies. If you don't want to
consume the values, you can use iterM
:
iterM (omapM_ f)
Since: conduit-1.3.0
foldMC :: Monad m => (a -> b -> m a) -> a -> ConduitT b o m a Source #
A monadic strict left fold.
Since: conduit-1.3.0
foldMCE :: (Monad m, MonoFoldable mono) => (a -> Element mono -> m a) -> a -> ConduitT mono o m a Source #
A monadic strict left fold on a chunked stream.
Since: conduit-1.3.0
foldMapMC :: (Monad m, Monoid w) => (a -> m w) -> ConduitT a o m w Source #
Apply the provided monadic mapping function and monoidal combine all values.
Since: conduit-1.3.0
foldMapMCE :: (Monad m, MonoFoldable mono, Monoid w) => (Element mono -> m w) -> ConduitT mono o m w Source #
Apply the provided monadic mapping function and monoidal combine all elements in the chunked stream.
Since: conduit-1.3.0
I/O
sinkFile :: MonadResource m => FilePath -> ConduitT ByteString o m () Source #
Stream all incoming data to the given file.
Since: conduit-1.3.0
sinkFileCautious :: MonadResource m => FilePath -> ConduitM ByteString o m () Source #
Cautious version of sinkFile
. The idea here is to stream the
values to a temporary file in the same directory of the destination
file, and only on successfully writing the entire file, moves it
atomically to the destination path.
In the event of an exception occurring, the temporary file will be deleted and no move will be made. If the application shuts down without running exception handling (such as machine failure or a SIGKILL), the temporary file will remain and the destination file will be untouched.
Since: conduit-1.3.0
:: MonadResource m | |
=> FilePath | temp directory |
-> String | filename pattern |
-> ConduitM ByteString o m FilePath |
Stream data into a temporary file in the given directory with the
given filename pattern, and return the temporary filename. The
temporary file will be automatically deleted when exiting the
active ResourceT
block, if it still exists.
Since: conduit-1.3.0
:: MonadResource m | |
=> String | filename pattern |
-> ConduitM ByteString o m FilePath |
Same as sinkTempFile
, but will use the default temp file
directory for the system as the first argument.
Since: conduit-1.3.0
sinkFileBS :: MonadResource m => FilePath -> ConduitT ByteString o m () Source #
sinkFile
specialized to ByteString
to help with type
inference.
Since: conduit-1.3.0
sinkHandle :: MonadIO m => Handle -> ConduitT ByteString o m () Source #
Stream all incoming data to the given Handle
. Note that this function
does not flush and will not close the Handle
when processing completes.
Since: conduit-1.3.0
sinkIOHandle :: MonadResource m => IO Handle -> ConduitT ByteString o m () Source #
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: conduit-1.3.0
printC :: (Show a, MonadIO m) => ConduitT a o m () Source #
Print all incoming values to stdout.
Since: conduit-1.3.0
stdoutC :: MonadIO m => ConduitT ByteString o m () Source #
sinkHandle
applied to stdout
.
Since: conduit-1.3.0
stderrC :: MonadIO m => ConduitT ByteString o m () Source #
sinkHandle
applied to stderr
.
Since: conduit-1.3.0
withSinkFile :: (MonadUnliftIO m, MonadIO n) => FilePath -> (ConduitM ByteString o n () -> m a) -> m a Source #
Like withBinaryFile
, but provides a sink to write bytes to.
Since: conduit-1.3.0
withSinkFileBuilder :: (MonadUnliftIO m, MonadIO n) => FilePath -> (ConduitM Builder o n () -> m a) -> m a Source #
Same as withSinkFile
, but lets you use a Builder
.
Since: conduit-1.3.0
withSinkFileCautious :: (MonadUnliftIO m, MonadIO n) => FilePath -> (ConduitM ByteString o n () -> m a) -> m a Source #
Like sinkFileCautious
, but uses the with
pattern instead of
MonadResource
.
Since: conduit-1.3.0
sinkHandleFlush :: MonadIO m => Handle -> ConduitM (Flush ByteString) o m () Source #
Stream incoming Flush
es, executing them on IO.Handle
Note that this function does not automatically close the Handle
when
processing completes
Since: conduit-1.3.0
Transformers
Pure
mapC :: Monad m => (a -> b) -> ConduitT a b m () Source #
Apply a transformation to all values in a stream.
Since: conduit-1.3.0
mapCE :: (Monad m, Functor f) => (a -> b) -> ConduitT (f a) (f b) m () Source #
Apply a transformation to all elements in a chunked stream.
Since: conduit-1.3.0
omapCE :: (Monad m, MonoFunctor mono) => (Element mono -> Element mono) -> ConduitT mono mono m () Source #
Apply a monomorphic transformation to all elements in a chunked stream.
Unlike mapE
, this will work on types like ByteString
and Text
which
are MonoFunctor
but not Functor
.
Since: conduit-1.3.0
concatMapC :: (Monad m, MonoFoldable mono) => (a -> mono) -> ConduitT a (Element mono) m () Source #
Apply the function to each value in the stream, resulting in a foldable value (e.g., a list). Then yield each of the individual values in that foldable value separately.
Generalizes concatMap, mapMaybe, and mapFoldable.
Since: conduit-1.3.0
concatMapCE :: (Monad m, MonoFoldable mono, Monoid w) => (Element mono -> w) -> ConduitT mono w m () Source #
Apply the function to each element in the chunked stream, resulting in a foldable value (e.g., a list). Then yield each of the individual values in that foldable value separately.
Generalizes concatMap, mapMaybe, and mapFoldable.
Since: conduit-1.3.0
takeC :: Monad m => Int -> ConduitT a a m () Source #
Stream up to n number of values downstream.
Note that, if downstream terminates early, not all values will be consumed.
If you want to force exactly the given number of values to be consumed,
see takeExactly
.
Since: conduit-1.3.0
takeCE :: (Monad m, IsSequence seq) => Index seq -> ConduitT seq seq m () Source #
Stream up to n number of elements downstream in a chunked stream.
Note that, if downstream terminates early, not all values will be consumed.
If you want to force exactly the given number of values to be consumed,
see takeExactlyE
.
Since: conduit-1.3.0
takeWhileC :: Monad m => (a -> Bool) -> ConduitT a a m () Source #
Stream all values downstream that match the given predicate.
Same caveats regarding downstream termination apply as with take
.
Since: conduit-1.3.0
takeWhileCE :: (Monad m, IsSequence seq) => (Element seq -> Bool) -> ConduitT seq seq m () Source #
Stream all elements downstream that match the given predicate in a chunked stream.
Same caveats regarding downstream termination apply as with takeE
.
Since: conduit-1.3.0
takeExactlyC :: Monad m => Int -> ConduitT a b m r -> ConduitT a b m r Source #
Consume precisely the given number of values and feed them downstream.
This function is in contrast to take
, which will only consume up to the
given number of values, and will terminate early if downstream terminates
early. This function will discard any additional values in the stream if
they are unconsumed.
Note that this function takes a downstream ConduitT
as a parameter, as
opposed to working with normal fusion. For more information, see
http://www.yesodweb.com/blog/2013/10/core-flaw-pipes-conduit, the section
titled "pipes and conduit: isolate".
Since: conduit-1.3.0
takeExactlyCE :: (Monad m, IsSequence a) => Index a -> ConduitT a b m r -> ConduitT a b m r Source #
Same as takeExactly
, but for chunked streams.
Since: conduit-1.3.0
concatC :: (Monad m, MonoFoldable mono) => ConduitT mono (Element mono) m () Source #
Flatten out a stream by yielding the values contained in an incoming
MonoFoldable
as individually yielded values.
Since: conduit-1.3.0
filterC :: Monad m => (a -> Bool) -> ConduitT a a m () Source #
Keep only values in the stream passing a given predicate.
Since: conduit-1.3.0
filterCE :: (IsSequence seq, Monad m) => (Element seq -> Bool) -> ConduitT seq seq m () Source #
Keep only elements in the chunked stream passing a given predicate.
Since: conduit-1.3.0
mapWhileC :: Monad m => (a -> Maybe b) -> ConduitT a b m () Source #
Map values as long as the result is Just
.
Since: conduit-1.3.0
Break up a stream of values into vectors of size n. The final vector may be smaller than n if the total number of values is not a strict multiple of n. No empty vectors will be yielded.
Since: conduit-1.3.0
scanlC :: Monad m => (a -> b -> a) -> a -> ConduitT b a m () Source #
Analog of scanl
for lists.
Since: conduit-1.3.0
concatMapAccumC :: Monad m => (a -> accum -> (accum, [b])) -> accum -> ConduitT a b m () Source #
concatMap
with an accumulator.
Since: conduit-1.3.0
intersperseC :: Monad m => a -> ConduitT a a m () Source #
Insert the given value between each two values in the stream.
Since: conduit-1.3.0
slidingWindowC :: (Monad m, IsSequence seq, Element seq ~ a) => Int -> ConduitT a seq m () Source #
Sliding window of values 1,2,3,4,5 with window size 2 gives [1,2],[2,3],[3,4],[4,5]
Best used with structures that support O(1) snoc.
Since: conduit-1.3.0
chunksOfCE :: (Monad m, IsSequence seq) => Index seq -> ConduitT seq seq m () Source #
Split input into chunk of size chunkSize
The last element may be smaller than the chunkSize
(see also
chunksOfExactlyE
which will not yield this last element)
Since: conduit-1.3.0
chunksOfExactlyCE :: (Monad m, IsSequence seq) => Index seq -> ConduitT seq seq m () Source #
Split input into chunk of size chunkSize
If the input does not split into chunks exactly, the remainder will be
leftover (see also chunksOfE
)
Since: conduit-1.3.0
Monadic
mapMC :: Monad m => (a -> m b) -> ConduitT a b m () Source #
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: conduit-1.3.0
mapMCE :: (Monad m, Traversable f) => (a -> m b) -> ConduitT (f a) (f b) m () Source #
Apply a monadic transformation to all elements in a chunked stream.
Since: conduit-1.3.0
omapMCE :: (Monad m, MonoTraversable mono) => (Element mono -> m (Element mono)) -> ConduitT mono mono m () Source #
Apply a monadic monomorphic transformation to all elements in a chunked stream.
Unlike mapME
, this will work on types like ByteString
and Text
which
are MonoFunctor
but not Functor
.
Since: conduit-1.3.0
concatMapMC :: (Monad m, MonoFoldable mono) => (a -> m mono) -> ConduitT a (Element mono) m () Source #
Apply the monadic function to each value in the stream, resulting in a foldable value (e.g., a list). Then yield each of the individual values in that foldable value separately.
Generalizes concatMapM, mapMaybeM, and mapFoldableM.
Since: conduit-1.3.0
filterMC :: Monad m => (a -> m Bool) -> ConduitT a a m () Source #
Keep only values in the stream passing a given monadic predicate.
Since: conduit-1.3.0
filterMCE :: (Monad m, IsSequence seq) => (Element seq -> m Bool) -> ConduitT seq seq m () Source #
Keep only elements in the chunked stream passing a given monadic predicate.
Since: conduit-1.3.0
iterMC :: Monad m => (a -> m ()) -> ConduitT a a m () Source #
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: conduit-1.3.0
scanlMC :: Monad m => (a -> b -> m a) -> a -> ConduitT b a m () Source #
Analog of scanl
for lists, monadic.
Since: conduit-1.3.0
mapAccumWhileMC :: Monad m => (a -> s -> m (Either s (s, b))) -> s -> ConduitT a b m s Source #
Monadic mapAccumWhileC
.
concatMapAccumMC :: Monad m => (a -> accum -> m (accum, [b])) -> accum -> ConduitT a b m () Source #
concatMapM
with an accumulator.
Since: conduit-1.3.0
Textual
encodeUtf8C :: (Monad m, Utf8 text binary) => ConduitT text binary m () Source #
Encode a stream of text as UTF8.
Since: conduit-1.3.0
decodeUtf8C :: MonadThrow m => ConduitT ByteString Text m () Source #
Decode a stream of binary data as UTF8.
Since: conduit-1.3.0
decodeUtf8LenientC :: Monad m => ConduitT ByteString Text m () Source #
Decode a stream of binary data as UTF8, replacing any invalid bytes with the Unicode replacement character.
Since: conduit-1.3.0
lineC :: (Monad m, IsSequence seq, Element seq ~ Char) => ConduitT seq o m r -> ConduitT seq o m r Source #
Stream in the entirety of a single line.
Like takeExactly
, this will consume the entirety of the line regardless of
the behavior of the inner Conduit.
Since: conduit-1.3.0
lineAsciiC :: (Monad m, IsSequence seq, Element seq ~ Word8) => ConduitT seq o m r -> ConduitT seq o m r Source #
Same as line
, but operates on ASCII/binary data.
Since: conduit-1.3.0
unlinesC :: (Monad m, IsSequence seq, Element seq ~ Char) => ConduitT seq seq m () Source #
Insert a newline character after each incoming chunk of data.
Since: conduit-1.3.0
unlinesAsciiC :: (Monad m, IsSequence seq, Element seq ~ Word8) => ConduitT seq seq m () Source #
Same as unlines
, but operates on ASCII/binary data.
Since: conduit-1.3.0
linesUnboundedC :: (Monad m, IsSequence seq, Element seq ~ Char) => ConduitT seq seq m () Source #
Convert a stream of arbitrarily-chunked textual data into a stream of data where each chunk represents a single line. Note that, if you have unknownuntrusted input, this function is unsafe/, since it would allow an attacker to form lines of massive length and exhaust memory.
Since: conduit-1.3.0
linesUnboundedAsciiC :: (Monad m, IsSequence seq, Element seq ~ Word8) => ConduitT seq seq m () Source #
Same as linesUnbounded
, but for ASCII/binary data.
Since: conduit-1.3.0
Builders
builderToByteString :: PrimMonad m => ConduitT Builder ByteString m () Source #
Incrementally execute builders and pass on the filled chunks as bytestrings.
Since: conduit-1.3.0
unsafeBuilderToByteString :: PrimMonad m => ConduitT Builder ByteString m () Source #
Incrementally execute builders on the given buffer and pass on the filled chunks as bytestrings. Note that, if the given buffer is too small for the execution of a build step, a larger one will be allocated.
WARNING: This conduit yields bytestrings that are NOT referentially transparent. Their content will be overwritten as soon as control is returned from the inner sink!
Since: conduit-1.3.0
builderToByteStringWith :: PrimMonad m => BufferAllocStrategy -> ConduitT Builder ByteString m () Source #
A conduit that incrementally executes builders and passes on the filled chunks as bytestrings to an inner sink.
INV: All bytestrings passed to the inner sink are non-empty.
Since: conduit-1.3.0
builderToByteStringFlush :: PrimMonad m => ConduitT (Flush Builder) (Flush ByteString) m () Source #
Same as builderToByteString
, but input and output are wrapped in
Flush
.
Since: conduit-1.3.0
builderToByteStringWithFlush :: PrimMonad m => BufferAllocStrategy -> ConduitT (Flush Builder) (Flush ByteString) m () Source #
Since: conduit-1.3.0
type BufferAllocStrategy = (IO Buffer, Int -> Buffer -> IO (IO Buffer)) Source #
A buffer allocation strategy (buf0, nextBuf)
specifies the initial
buffer to use and how to compute a new buffer nextBuf minSize buf
with at
least size minSize
from a filled buffer buf
. The double nesting of the
IO
monad helps to ensure that the reference to the filled buffer buf
is
lost as soon as possible, but the new buffer doesn't have to be allocated
too early.
Since: conduit-1.3.0
allNewBuffersStrategy :: Int -> BufferAllocStrategy Source #
The simplest buffer allocation strategy: whenever a buffer is requested, allocate a new one that is big enough for the next build step to execute.
NOTE that this allocation strategy may spill quite some memory upon direct insertion of a bytestring by the builder. Thats no problem for garbage collection, but it may lead to unreasonably high memory consumption in special circumstances.
Since: conduit-1.3.0
reuseBufferStrategy :: IO Buffer -> BufferAllocStrategy Source #
An unsafe, but possibly more efficient buffer allocation strategy: reuse the buffer, if it is big enough for the next build step to execute.
Since: conduit-1.3.0
Special
:: (PrimMonad m, Vector v e, PrimMonad n, PrimState m ~ PrimState n) | |
=> Int | size |
-> ((e -> n ()) -> ConduitT i Void m r) | |
-> ConduitT i (v e) m r |
Generally speaking, yielding values from inside a Conduit requires some allocation for constructors. This can introduce an overhead, similar to the overhead needed to represent a list of values instead of a vector. This overhead is even more severe when talking about unboxed values.
This combinator allows you to overcome this overhead, and efficiently fill up vectors. It takes two parameters. The first is the size of each mutable vector to be allocated. The second is a function. The function takes an argument which will yield the next value into a mutable vector.
Under the surface, this function uses a number of tricks to get high performance. For more information on both usage and implementation, please see: https://www.fpcomplete.com/user/snoyberg/library-documentation/vectorbuilder
Since: conduit-1.3.0
mapAccumS :: Monad m => (a -> s -> ConduitT b Void m s) -> s -> ConduitT () b m () -> ConduitT a Void m s Source #
Consume a source with a strict accumulator, in a way piecewise defined by a controlling stream. The latter will be evaluated until it terminates.
>>>
let f a s = liftM (:s) $ mapC (*a) =$ CL.take a
>>>
reverse $ runIdentity $ yieldMany [0..3] $$ mapAccumS f [] (yieldMany [1..])
[[],[1],[4,6],[12,15,18]] :: [[Int]]
peekForever :: Monad m => ConduitT i o m () -> ConduitT i o m () Source #
Run a consuming conduit repeatedly, only stopping when there is no more data available from upstream.
Since: conduit-1.3.0
peekForeverE :: (Monad m, MonoFoldable i) => ConduitT i o m () -> ConduitT i o m () Source #
Run a consuming conduit repeatedly, only stopping when there is no more data available from upstream.
In contrast to peekForever
, this function will ignore empty
chunks of data. So for example, if a stream of data contains an
empty ByteString
, it is still treated as empty, and the consuming
function is not called.
Since: conduit-1.3.0
Monadic lifting
class Monad m => MonadIO (m :: * -> *) where #
Monads in which IO
computations may be embedded.
Any monad built by applying a sequence of monad transformers to the
IO
monad will be an instance of this class.
Instances should satisfy the following laws, which state that liftIO
is a transformer of monads:
Instances
class MonadTrans (t :: (* -> *) -> * -> *) where #
The class of monad transformers. Instances should satisfy the
following laws, which state that lift
is a monad transformation:
lift :: Monad m => m a -> t m a #
Lift a computation from the argument monad to the constructed monad.
Instances
class Monad m => MonadThrow (m :: * -> *) where #
A class for monads in which exceptions may be thrown.
Instances should obey the following law:
throwM e >> x = throwM e
In other words, throwing an exception short-circuits the rest of the monadic computation.
throwM :: Exception e => e -> m a #
Throw an exception. Note that this throws when this action is run in
the monad m
, not when it is applied. It is a generalization of
Control.Exception's throwIO
.
Should satisfy the law:
throwM e >> f = throwM e
Instances
class MonadIO m => MonadUnliftIO (m :: * -> *) where #
Monads which allow their actions to be run in IO
.
While MonadIO
allows an IO
action to be lifted into another
monad, this class captures the opposite concept: allowing you to
capture the monadic context. Note that, in order to meet the laws
given below, the intuition is that a monad must have no monadic
state, but may have monadic context. This essentially limits
MonadUnliftIO
to ReaderT
and IdentityT
transformers on top of
IO
.
Laws. For any value u
returned by askUnliftIO
, it must meet the
monad transformer laws as reformulated for MonadUnliftIO
:
unliftIO u . return = return
unliftIO u (m >>= f) = unliftIO u m >>= unliftIO u . f
The third is a currently nameless law which ensures that the current context is preserved.
askUnliftIO >>= (u -> liftIO (unliftIO u m)) = m
If you have a name for this, please submit it in a pull request for great glory.
Since: unliftio-core-0.1.0.0
askUnliftIO :: m (UnliftIO m) #
Capture the current monadic context, providing the ability to
run monadic actions in IO
.
See UnliftIO
for an explanation of why we need a helper
datatype here.
@since 0.1.0.0
withRunInIO :: ((forall a. m a -> IO a) -> IO b) -> m b #
Convenience function for capturing the monadic context and running an IO
action with a runner function. The runner function is used to run a monadic
action m
in IO
.
Since: unliftio-core-0.1.0.0
Instances
MonadUnliftIO IO | |
Defined in Control.Monad.IO.Unlift | |
MonadUnliftIO m => MonadUnliftIO (ResourceT m) | Since: resourcet-1.1.10 |
Defined in Control.Monad.Trans.Resource.Internal | |
MonadUnliftIO m => MonadUnliftIO (IdentityT m) | |
Defined in Control.Monad.IO.Unlift | |
MonadUnliftIO m => MonadUnliftIO (ReaderT r m) | |
Defined in Control.Monad.IO.Unlift |
class Monad m => PrimMonad (m :: * -> *) where #
Instances
PrimMonad IO | |
PrimMonad (ST s) | |
PrimMonad m => PrimMonad (MaybeT m) | |
PrimMonad m => PrimMonad (ListT m) | |
PrimMonad m => PrimMonad (ResourceT m) | |
PrimMonad m => PrimMonad (ExceptT e m) | |
PrimMonad m => PrimMonad (IdentityT m) | |
(Error e, PrimMonad m) => PrimMonad (ErrorT e m) | |
PrimMonad m => PrimMonad (StateT s m) | |
PrimMonad m => PrimMonad (StateT s m) | |
(Monoid w, PrimMonad m) => PrimMonad (WriterT w m) | |
(Monoid w, PrimMonad m) => PrimMonad (WriterT w m) | |
(Monoid w, PrimMonad m) => PrimMonad (AccumT w m) | |
PrimMonad m => PrimMonad (SelectT r m) | |
PrimMonad m => PrimMonad (ContT r m) | |
PrimMonad m => PrimMonad (ReaderT r m) | |
PrimMonad m => PrimMonad (ConduitT i o m) # | |
(Monoid w, PrimMonad m) => PrimMonad (RWST r w s m) | |
(Monoid w, PrimMonad m) => PrimMonad (RWST r w s m) | |
PrimMonad m => PrimMonad (Pipe l i o u m) # | |
ResourceT
class MonadIO m => MonadResource (m :: * -> *) #
A Monad
which allows for safe resource allocation. In theory, any monad
transformer stack which includes a ResourceT
can be an instance of
MonadResource
.
Note: runResourceT
has a requirement for a MonadUnliftIO 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
Instances
data ResourceT (m :: * -> *) 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
Instances
runResourceT :: MonadUnliftIO m => ResourceT m 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.
NOTE Since version 1.2.0, this function will throw a
ResourceCleanupException
if any of the cleanup functions throw an
exception.
Since: resourcet-0.3.0
Acquire
withAcquire :: MonadUnliftIO m => Acquire a -> (a -> m b) -> m b #
Longer name for with
, in case with
is not obvious enough in context.
Since: resourcet-1.2.0
allocateAcquire :: MonadResource m => Acquire a -> m (ReleaseKey, a) #
Allocate a resource and register an action with the MonadResource
to
free the resource.
Since: resourcet-1.1.0
:: IO a | acquire the resource |
-> (a -> ReleaseType -> IO ()) | free the resource |
-> Acquire a |
Same as mkAcquire
, but the cleanup function will be informed of how
cleanup was initiated. This allows you to distinguish, for example, between
normal and exceptional exits.
Since: resourcet-1.1.2
Create an Acquire
value using the given allocate and free functions.
Since: resourcet-1.1.0
data ReleaseType #
The way in which a release is called.
Since: resourcet-1.1.2
Instances
A method for acquiring a scarce resource, providing the means of freeing
it when no longer needed. This data type provides
Functor
/Applicative
/Monad
instances for composing different resources
together. You can allocate these resources using either the bracket
pattern (via with
) or using ResourceT
(via allocateAcquire
).
This concept was originally introduced by Gabriel Gonzalez and described at: http://www.haskellforall.com/2013/06/the-resource-applicative.html. The implementation in this package is slightly different, due to taking a different approach to async exception safety.
Since: resourcet-1.1.0
Instances
Monad Acquire | |
Functor Acquire | |
Applicative Acquire | |
MonadIO Acquire | |
Defined in Data.Acquire.Internal |
Pure pipelines
Identity functor and monad. (a non-strict monad)
Since: base-4.8.0.0
Identity | |
|