Yield each of the values contained by the given MonoFoldable.
This will work on many data structures, including lists, ByteStrings, and Vectors.
Subject to fusion
:: a typeCtrl KGHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05
Moduleconduit-1.3.6.1Haskell2010
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.
module Data.Conduit
module Data.Conduit.Lift
Yield each of the values contained by the given MonoFoldable.
This will work on many data structures, including lists, ByteStrings, and Vectors.
Subject to fusion
Generate a producer by yielding each of the strict chunks in a LazySequence.
For more information, see toChunks.
Subject to fusion
Stream the contents of a file as binary data.
Same as sourceFile. The alternate name is a holdover from an older version, when sourceFile was more polymorphic than it is today.
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.
Same as sourceHandle, but instead of allocating a new buffer for each
incoming chunk of data, reuses the same buffer. Therefore, the ByteStrings
yielded by this function are not referentially transparent between two
different yields.
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.
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.
Like withBinaryFile, but provides a source to read bytes from.
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.
sourceDirectoryDeep :: MonadResource m=> BoolFollow directory symlinks
-> FilePathRoot 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.
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
Consume all values from the stream and return as a list. Note that this will pull all values into memory.
Subject to fusion
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
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
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
Consume and discard all remaining values in the stream.
Subject to fusion
Same as await, but discards any leading onull values.
Stream all incoming data to the given file.
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.
sinkTempFile :: MonadResource m=> FilePathtemp directory
-> Stringfilename pattern
-> ConduitM ByteString o m FilePathStream 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.
sinkSystemTempFile :: MonadResource m=> Stringfilename pattern
-> ConduitM ByteString o m FilePathSame as sinkTempFile, but will use the default temp file directory for the system as the first argument.
sinkFile specialized to ByteString to help with type inference.
Stream all incoming data to the given Handle. Note that this function
does not flush and will not close the Handle when processing completes.
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.
Like withBinaryFile, but provides a sink to write bytes to.
Same as withSinkFile, but lets you use a BB.Builder.
Like sinkFileCautious, but uses the with pattern instead of
MonadResource.
Stream incoming Flushes, executing them on IO.Handle
Note that this function does not automatically close the Handle when
processing completes
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.
Incrementally execute builders and pass on the filled chunks as bytestrings.
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!
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.
Same as builderToByteString, but input and output are wrapped in Flush.
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.
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.
An unsafe, but possibly more efficient buffer allocation strategy: reuse the buffer, if it is big enough for the next build step to execute.
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 areverse $ runIdentity $ yieldMany [0..3] $$ mapAccumS f [] (yieldMany [1..])[[],[1],[4,6],[12,15,18]] :: [[Int]]
Run a consuming conduit repeatedly, only stopping when there is no more data available from upstream.
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.
Generate a producer from a seed value.
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.
Produces an infinite stream of repeated applications of f to x.
Produce an infinite stream consisting entirely of the given value.
Produce a finite stream consisting of n copies of the given value.
Repeatedly run the given action and yield all values it produces.
Repeatedly run the given action and yield all values it produces, until
the provided predicate returns False.
Perform the given action n times, yielding each result.
sourceHandle applied to stdin.
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]
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.
Drop all values which match the given predicate.
Note: you likely want to use it with monadic composition. See the docs for dropC.
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.
Monoidally combine all values in the stream.
foldCE :: (Monad m, MonoFoldable mono, Monoid (Element mono)) => ConduitT mono o m (Element mono)Monoidally combine all elements in the chunked stream.
A strict left fold.
A strict left fold on a chunked stream.
Apply the provided mapping function and monoidal combine all values.
Apply the provided mapping function and monoidal combine all elements of the chunked stream.
Check that all values in the stream return True.
Subject to shortcut logic: at the first False, consumption of the stream will stop.
Check that all elements in the chunked stream return True.
Subject to shortcut logic: at the first False, consumption of the stream will stop.
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.
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.
Are all values in the stream True?
Consumption stops once the first False is encountered.
Are all elements in the chunked stream True?
Consumption stops once the first False is encountered.
Are any values in the stream True?
Consumption stops once the first True is encountered.
Are any elements in the chunked stream True?
Consumption stops once the first True is encountered.
Alternatively combine all values in the stream.
Are any values in the stream equal to the given value?
Stops consuming as soon as a match is found.
Are any elements in the chunked stream equal to the given element?
Stops consuming as soon as a match is found.
Are no values in the stream equal to the given value?
Stops consuming as soon as a match is found.
Are no elements in the chunked stream equal to the given element?
Stops consuming as soon as a match is found.
Take a single value from the stream, if available.
Same as headC, but returns a default value if none are available from the stream.
Get the next element in the chunked stream.
View the next value in the stream without consuming it.
View the next element in the chunked stream without consuming it.
Retrieve the last value in the stream, if present.
Same as lastC, but returns a default value if none are available from the stream.
Retrieve the last element in the chunked stream, if present.
Count how many values are in the stream.
Count how many elements are in the chunked stream.
Count how many values in the stream pass the given predicate.
Count how many elements in the chunked stream pass the given predicate.
Get the largest value in the stream, if present.
maximumCE :: (Monad m, IsSequence seq, Ord (Element seq)) => ConduitT seq o m (Maybe (Element seq))Get the largest element in the chunked stream, if present.
Get the smallest value in the stream, if present.
minimumCE :: (Monad m, IsSequence seq, Ord (Element seq)) => ConduitT seq o m (Maybe (Element seq))Get the smallest element in the chunked stream, if present.
True if there are no values in the stream.
This function does not modify the stream.
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.
Get the sum of all values in the stream.
Get the sum of all elements in the chunked stream.
Get the product of all values in the stream.
productCE :: (Monad m, MonoFoldable mono, Num (Element mono)) => ConduitT mono o m (Element mono)Get the product of all elements in the chunked stream.
Find the first matching value.
Apply the action to all values in the stream.
Note: if you want to pass the values instead of consuming them, use
iterM instead.
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)A monadic strict left fold.
A monadic strict left fold on a chunked stream.
Apply the provided monadic mapping function and monoidal combine all values.
Apply the provided monadic mapping function and monoidal combine all elements in the chunked stream.
Print all incoming values to stdout.
sinkHandle applied to stdout.
sinkHandle applied to stderr.
Apply a transformation to all values in a stream.
Apply a transformation to all elements in a chunked stream.
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.
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.
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.
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.
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.
Stream all values downstream that match the given predicate.
Same caveats regarding downstream termination apply as with take.
Stream all elements downstream that match the given predicate in a chunked stream.
Same caveats regarding downstream termination apply as with takeE.
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".
Same as takeExactly, but for chunked streams.
Flatten out a stream by yielding the values contained in an incoming
MonoFoldable as individually yielded values.
Keep only values in the stream passing a given predicate.
Keep only elements in the chunked stream passing a given predicate.
Map values as long as the result is Just.
Analog of Prelude.scanl for lists.
mapWhileC with a break condition dependent on a strict accumulator.
Equivalently, CL.mapAccum as long as the result is Right. Instead of
producing a leftover, the breaking input determines the resulting
accumulator via Left.
concatMap with an accumulator.
Insert the given value between each two values in the stream.
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.
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)
Split input into chunk of size chunkSize
If the input does not split into chunks exactly, the remainder will be
leftover (see also chunksOfE)
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_.
Apply a monadic transformation to all elements in a chunked stream.
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.
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.
Keep only values in the stream passing a given monadic predicate.
Keep only elements in the chunked stream passing a given monadic predicate.
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)Analog of Prelude.scanl for lists, monadic.
Monadic mapAccumWhileC.
concatMapM with an accumulator.
Encode a stream of text as UTF8.
Decode a stream of binary data as UTF8.
Decode a stream of binary data as UTF8, replacing any invalid bytes with the Unicode replacement character.
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.
Same as line, but operates on ASCII/binary data.
Insert a newline character after each incoming chunk of data.
Same as unlines, but operates on ASCII/binary data.
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.
linesUnboundedAsciiC :: (Monad m, IsSequence seq, Element seq ~ Word8) => ConduitT seq seq m ()Same as linesUnbounded, but for ASCII/binary data.
vectorBuilderC 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
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:
liftIO :: IO a -> m aLift a computation from the IO monad. This allows us to run IO computations in any monadic stack, so long as it supports these kinds of operations (i.e. IO is the base monad for the stack).
import Control.Monad.Trans.State -- from the "transformers" library
printState :: Show s => StateT s IO ()
printState = do
state <- get
liftIO $ print stateHad we omitted liftIO, we would have ended up with this error:
• Couldn't match type ‘IO’ with ‘StateT s IO’
Expected type: StateT s IO ()
Actual type: IO ()The important part here is the mismatch between StateT s IO () and IO ().
Luckily, we know of a function that takes an IO a and returns an (m a): liftIO,
enabling us to run the program and see the expected results:
> evalStateT printState "hello"
"hello"
> evalStateT printState 3
3
MonadIO IODefined in base-4.20.2.0 · Control.Monad.IO.ClassMonadIO AcquireDefined in resourcet-1.3.0 · Data.Acquire.InternalMonadIO QDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.SyntaxMonadIO m => MonadIO (CatchT m)Defined in exceptions-0.10.9 · Control.Monad.Catch.PureMonadIO m => MonadIO (ResourceT m)Defined in resourcet-1.3.0 · Control.Monad.Trans.Resource.InternalMonadIO m => MonadIO (MaybeT m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.MaybeMonadIO m => MonadIO (ExceptT e m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.ExceptMonadIO m => MonadIO (IdentityT m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.IdentityMonadIO m => MonadIO (ReaderT r m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.ReaderMonadIO m => MonadIO (SelectT r m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.SelectMonadIO m => MonadIO (StateT s m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.State.LazyMonadIO m => MonadIO (StateT s m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.State.StrictMonadIO m => MonadIO (WriterT w m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.CPS(Monoid w, MonadIO m) => MonadIO (WriterT w m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.Lazy(Monoid w, MonadIO m) => MonadIO (WriterT w m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.Strict(Monoid w, Functor m, MonadIO m) => MonadIO (AccumT w m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.AccumMonadIO m => MonadIO (ConduitT i o m)Defined in conduit-1.3.6.1 · Data.Conduit.Internal.ConduitMonadIO m => MonadIO (ContT r m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.ContMonadIO m => MonadIO (RWST r w s m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.RWS.CPS(Monoid w, MonadIO m) => MonadIO (RWST r w s m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.RWS.Lazy(Monoid w, MonadIO m) => MonadIO (RWST r w s m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.RWS.StrictMonadIO m => MonadIO (Pipe l i o u m)Defined in conduit-1.3.6.1 · Data.Conduit.Internal.Pipeclass (forall (m :: Type -> Type). Monad m => Monad (t m)) => MonadTrans (t :: (Type -> Type) -> Type -> Type) whereThe class of monad transformers.
For any monad m, the result t m should also be a monad,
and lift should be a monad transformation from m to t m,
i.e. it should satisfy the following laws:
Since 0.6.0.0 and for GHC 8.6 and later, the requirement that t m
be a Monad is enforced by the implication constraint
forall m. Monad m => Monad (t m) enabled by the
QuantifiedConstraints extension.
These versions of GHC have a bug (https://gitlab.haskell.org/ghc/ghc/-/issues/20582) which causes constraints like
(MonadTrans t, forall m. Monad m => Monad (t m)) => ...
to be reported as ambiguous. For transformers 0.6 and later, this can be fixed by removing the second constraint, which is implied by the first.
MonadTrans CatchTDefined in exceptions-0.10.9 · Control.Monad.Catch.PureMonadTrans ResourceTDefined in resourcet-1.3.0 · Control.Monad.Trans.Resource.InternalMonadTrans MaybeTDefined in transformers-0.6.1.1 · Control.Monad.Trans.MaybeMonoid w => MonadTrans (AccumT w)Defined in transformers-0.6.1.1 · Control.Monad.Trans.AccumMonoid w => MonadTrans (WriterT w)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.LazyMonoid w => MonadTrans (WriterT w)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.StrictMonadTrans IdentityTDefined in transformers-0.6.1.1 · Control.Monad.Trans.IdentityMonadTrans (ExceptT e)Defined in transformers-0.6.1.1 · Control.Monad.Trans.ExceptMonadTrans (ReaderT r)Defined in transformers-0.6.1.1 · Control.Monad.Trans.ReaderMonadTrans (SelectT r)Defined in transformers-0.6.1.1 · Control.Monad.Trans.SelectMonadTrans (StateT s)Defined in transformers-0.6.1.1 · Control.Monad.Trans.State.LazyMonadTrans (StateT s)Defined in transformers-0.6.1.1 · Control.Monad.Trans.State.StrictMonadTrans (WriterT w)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.CPSMonadTrans (ConduitT i o)Defined in conduit-1.3.6.1 · Data.Conduit.Internal.ConduitMonadTrans (ContT r)Defined in transformers-0.6.1.1 · Control.Monad.Trans.ContMonoid w => MonadTrans (RWST r w s)Defined in transformers-0.6.1.1 · Control.Monad.Trans.RWS.LazyMonoid w => MonadTrans (RWST r w s)Defined in transformers-0.6.1.1 · Control.Monad.Trans.RWS.StrictMonadTrans (RWST r w s)Defined in transformers-0.6.1.1 · Control.Monad.Trans.RWS.CPSMonadTrans (Pipe l i o u)Defined in conduit-1.3.6.1 · Data.Conduit.Internal.PipeA class for monads in which exceptions may be thrown.
Instances should obey the following law:
throwM e >> x = throwM eIn other words, throwing an exception short-circuits the rest of the monadic computation.
throwM :: (HasCallStack, Exception e) => e -> m aThrow 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 eMonadThrow STMDefined in exceptions-0.10.9 · Control.Monad.CatchMonadThrow MaybeDefined in exceptions-0.10.9 · Control.Monad.CatchMonadThrow IODefined in exceptions-0.10.9 · Control.Monad.CatchMonadThrow QDefined in exceptions-0.10.9 · Control.Monad.CatchMonadThrow []Defined in exceptions-0.10.9 · Control.Monad.CatchMonadThrow (ST s)Defined in exceptions-0.10.9 · Control.Monad.CatchMonadThrow m => MonadThrow (ResourceT m)Defined in resourcet-1.3.0 · Control.Monad.Trans.Resource.InternalMonadThrow m => MonadThrow (MaybeT m)Defined in exceptions-0.10.9 · Control.Monad.CatchThrows exceptions into the base monad.
Monad m => MonadThrow (CatchT m)Defined in exceptions-0.10.9 · Control.Monad.Catch.Puree ~ SomeException => MonadThrow (Either e)Defined in exceptions-0.10.9 · Control.Monad.CatchMonadThrow m => MonadThrow (ExceptT e m)Defined in exceptions-0.10.9 · Control.Monad.CatchThrows exceptions into the base monad.
MonadThrow m => MonadThrow (IdentityT m)Defined in exceptions-0.10.9 · Control.Monad.CatchMonadThrow m => MonadThrow (ReaderT r m)Defined in exceptions-0.10.9 · Control.Monad.CatchMonadThrow m => MonadThrow (StateT s m)Defined in exceptions-0.10.9 · Control.Monad.CatchMonadThrow m => MonadThrow (StateT s m)Defined in exceptions-0.10.9 · Control.Monad.Catch(MonadThrow m, Monoid w) => MonadThrow (WriterT w m)Defined in exceptions-0.10.9 · Control.Monad.Catch(MonadThrow m, Monoid w) => MonadThrow (WriterT w m)Defined in exceptions-0.10.9 · Control.Monad.CatchMonadThrow m => MonadThrow (ConduitT i o m)Defined in conduit-1.3.6.1 · Data.Conduit.Internal.ConduitMonadThrow m => MonadThrow (ContT r m)Defined in exceptions-0.10.9 · Control.Monad.Catch(MonadThrow m, Monoid w) => MonadThrow (RWST r w s m)Defined in exceptions-0.10.9 · Control.Monad.Catch(MonadThrow m, Monoid w) => MonadThrow (RWST r w s m)Defined in exceptions-0.10.9 · Control.Monad.CatchMonadThrow m => MonadThrow (Pipe l i o u m)Defined in conduit-1.3.6.1 · Data.Conduit.Internal.PipeMonads 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 function run provided by withRunInIO, it must meet the
monad transformer laws as reformulated for MonadUnliftIO:
run . return = returnrun (m >>= f) = run m >>= run . fInstances of MonadUnliftIO must also satisfy the following laws:
withRunInIO (\run -> run m) = m
withRunInIO (\_ -> m) = liftIO m
As an example of an invalid instance, a naive implementation of
MonadUnliftIO (StateT s m) might be
withRunInIO inner =
StateT $ \s ->
withRunInIO $ \run ->
inner (run . flip evalStateT s)
This breaks the identity law because the inner run m would throw away
any state changes in m.
withRunInIO :: ((forall a. m a -> IO a) -> IO b) -> m bConvenience 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.
MonadUnliftIO IODefined in unliftio-core-0.2.1.0 · Control.Monad.IO.UnliftMonadUnliftIO m => MonadUnliftIO (ResourceT m)Defined in resourcet-1.3.0 · Control.Monad.Trans.Resource.InternalMonadUnliftIO m => MonadUnliftIO (IdentityT m)Defined in unliftio-core-0.2.1.0 · Control.Monad.IO.UnliftMonadUnliftIO m => MonadUnliftIO (ReaderT r m)Defined in unliftio-core-0.2.1.0 · Control.Monad.IO.UnliftClass of monads which can perform primitive state-transformer actions.
PrimMonad IODefined in primitive-0.9.1.0 · Control.Monad.PrimitivePrimMonad (ST s)Defined in primitive-0.9.1.0 · Control.Monad.PrimitivePrimMonad (ST s)Defined in primitive-0.9.1.0 · Control.Monad.PrimitivePrimMonad m => PrimMonad (ResourceT m)Defined in resourcet-1.3.0 · Control.Monad.Trans.Resource.InternalPrimMonad m => PrimMonad (MaybeT m)Defined in primitive-0.9.1.0 · Control.Monad.PrimitivePrimMonad m => PrimMonad (ExceptT e m)Defined in primitive-0.9.1.0 · Control.Monad.PrimitivePrimMonad m => PrimMonad (IdentityT m)Defined in primitive-0.9.1.0 · Control.Monad.PrimitivePrimMonad m => PrimMonad (ReaderT r m)Defined in primitive-0.9.1.0 · Control.Monad.PrimitivePrimMonad m => PrimMonad (SelectT r m)Defined in primitive-0.9.1.0 · Control.Monad.PrimitivePrimMonad m => PrimMonad (StateT s m)Defined in primitive-0.9.1.0 · Control.Monad.PrimitivePrimMonad m => PrimMonad (StateT s m)Defined in primitive-0.9.1.0 · Control.Monad.Primitive(Monoid w, PrimMonad m) => PrimMonad (AccumT w m)Defined in primitive-0.9.1.0 · Control.Monad.Primitive(Monoid w, PrimMonad m) => PrimMonad (WriterT w m)Defined in primitive-0.9.1.0 · Control.Monad.Primitive(Monoid w, PrimMonad m) => PrimMonad (WriterT w m)Defined in primitive-0.9.1.0 · Control.Monad.Primitive(Monoid w, PrimMonad m) => PrimMonad (WriterT w m)Defined in primitive-0.9.1.0 · Control.Monad.PrimitivePrimMonad m => PrimMonad (ConduitT i o m)Defined in conduit-1.3.6.1 · Data.Conduit.Internal.ConduitPrimMonad m => PrimMonad (ContT r m)Defined in primitive-0.9.1.0 · Control.Monad.Primitive(Monoid w, PrimMonad m) => PrimMonad (RWST r w s m)Defined in primitive-0.9.1.0 · Control.Monad.Primitive(Monoid w, PrimMonad m) => PrimMonad (RWST r w s m)Defined in primitive-0.9.1.0 · Control.Monad.Primitive(Monoid w, PrimMonad m) => PrimMonad (RWST r w s m)Defined in primitive-0.9.1.0 · Control.Monad.PrimitivePrimMonad m => PrimMonad (Pipe l i o u m)Defined in conduit-1.3.6.1 · Data.Conduit.Internal.PipeA 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
MonadIO m => MonadResource (ResourceT m)Defined in resourcet-1.3.0 · Control.Monad.Trans.Resource.InternalMonadResource m => MonadResource (MaybeT m)Defined in resourcet-1.3.0 · Control.Monad.Trans.Resource.InternalMonadResource m => MonadResource (ExceptT e m)Defined in resourcet-1.3.0 · Control.Monad.Trans.Resource.InternalMonadResource m => MonadResource (IdentityT m)Defined in resourcet-1.3.0 · Control.Monad.Trans.Resource.InternalMonadResource m => MonadResource (ReaderT r m)Defined in resourcet-1.3.0 · Control.Monad.Trans.Resource.InternalMonadResource m => MonadResource (StateT s m)Defined in resourcet-1.3.0 · Control.Monad.Trans.Resource.InternalMonadResource m => MonadResource (StateT s m)Defined in resourcet-1.3.0 · Control.Monad.Trans.Resource.Internal(Monoid w, MonadResource m) => MonadResource (WriterT w m)Defined in resourcet-1.3.0 · Control.Monad.Trans.Resource.Internal(Monoid w, MonadResource m) => MonadResource (WriterT w m)Defined in resourcet-1.3.0 · Control.Monad.Trans.Resource.InternalMonadResource m => MonadResource (ConduitT i o m)Defined in conduit-1.3.6.1 · Data.Conduit.Internal.ConduitMonadResource m => MonadResource (ContT r m)Defined in resourcet-1.3.0 · Control.Monad.Trans.Resource.Internal(Monoid w, MonadResource m) => MonadResource (RWST r w s m)Defined in resourcet-1.3.0 · Control.Monad.Trans.Resource.Internal(Monoid w, MonadResource m) => MonadResource (RWST r w s m)Defined in resourcet-1.3.0 · Control.Monad.Trans.Resource.InternalMonadResource m => MonadResource (Pipe l i o u m)Defined in conduit-1.3.6.1 · Data.Conduit.Internal.PipeThe 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
MonadTrans ResourceTDefined in resourcet-1.3.0 · Control.Monad.Trans.Resource.InternalMonadRWS r w s m => MonadRWS r w s (ResourceT m)Defined in resourcet-1.3.0 · Control.Monad.Trans.Resource.InternalMonadError e m => MonadError e (ResourceT m)Defined in resourcet-1.3.0 · Control.Monad.Trans.Resource.InternalMonadReader r m => MonadReader r (ResourceT m)Defined in resourcet-1.3.0 · Control.Monad.Trans.Resource.InternalMonadState s m => MonadState s (ResourceT m)Defined in resourcet-1.3.0 · Control.Monad.Trans.Resource.InternalMonadWriter w m => MonadWriter w (ResourceT m)Defined in resourcet-1.3.0 · Control.Monad.Trans.Resource.InternalMonad m => Monad (ResourceT m)Defined in resourcet-1.3.0 · Control.Monad.Trans.Resource.InternalFunctor m => Functor (ResourceT m)Defined in resourcet-1.3.0 · Control.Monad.Trans.Resource.InternalMonadFix m => MonadFix (ResourceT m)Defined in resourcet-1.3.0 · Control.Monad.Trans.Resource.InternalMonadFail m => MonadFail (ResourceT m)Defined in resourcet-1.3.0 · Control.Monad.Trans.Resource.InternalApplicative m => Applicative (ResourceT m)Defined in resourcet-1.3.0 · Control.Monad.Trans.Resource.InternalAlternative m => Alternative (ResourceT m)Defined in resourcet-1.3.0 · Control.Monad.Trans.Resource.InternalSince 1.1.5
MonadPlus m => MonadPlus (ResourceT m)Defined in resourcet-1.3.0 · Control.Monad.Trans.Resource.InternalSince 1.1.5
MonadIO m => MonadIO (ResourceT m)Defined in resourcet-1.3.0 · Control.Monad.Trans.Resource.InternalMonadCont m => MonadCont (ResourceT m)Defined in resourcet-1.3.0 · Control.Monad.Trans.Resource.InternalMonadCatch m => MonadCatch (ResourceT m)Defined in resourcet-1.3.0 · Control.Monad.Trans.Resource.InternalMonadMask m => MonadMask (ResourceT m)Defined in resourcet-1.3.0 · Control.Monad.Trans.Resource.InternalMonadThrow m => MonadThrow (ResourceT m)Defined in resourcet-1.3.0 · Control.Monad.Trans.Resource.InternalPrimMonad m => PrimMonad (ResourceT m)Defined in resourcet-1.3.0 · Control.Monad.Trans.Resource.InternalMonadUnliftIO m => MonadUnliftIO (ResourceT m)Defined in resourcet-1.3.0 · Control.Monad.Trans.Resource.InternalMonadIO m => MonadResource (ResourceT m)Defined in resourcet-1.3.0 · Control.Monad.Trans.Resource.Internaltype PrimState (ResourceT m) = PrimState mDefined in resourcet-1.3.0 · Control.Monad.Trans.Resource.InternalUnwrap 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.
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.
The way in which a release is called.
Show ReleaseTypeDefined in resourcet-1.3.0 · Data.Acquire.InternalDeprecated. Use ReleaseExceptionWith, which has the exception in the constructor. This pattern synonym hides the exception and can obscure problems.
Create an Acquire value using the given allocate and free functions.
To acquire and free the resource in an arbitrary monad with MonadUnliftIO, do the following:
acquire <- withRunInIO $ \runInIO ->
return $ mkAcquire (runInIO create) (runInIO . free)Note that this is only safe if the Acquire is run and freed within the same monadic scope it was created in.
mkAcquireType :: IO aacquire the resource
-> (a -> ReleaseType -> IO ())free the resource
-> Acquire aSame 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.
To acquire and free the resource in an arbitrary monad with MonadUnliftIO, do the following:
acquire <- withRunInIO $ \runInIO ->
return $ mkAcquireType (runInIO create) (\a -> runInIO . free a)Note that this is only safe if the Acquire is run and freed within the same monadic scope it was created in.
Allocate a resource and register an action with the MonadResource to
free the resource.
Longer name for with, in case with is not obvious enough in context.
Identity functor and monad. (a non-strict monad)
fmap (+1) (Identity 0)Identity 1
Identity [1, 2, 3] <> Identity [4, 5, 6]Identity [1,2,3,4,5,6]
>>> do
x <- Identity 10
y <- Identity (x + 5)
pure (x + y)
Identity 25
IdentityrunIdentity :: aMonad IdentityDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.IdentityFunctor IdentityDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.IdentityMonadFix IdentityDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.IdentityApplicative IdentityDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.IdentityFoldable IdentityDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.IdentityTraversable IdentityDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.TraversableMonadZip IdentityDefined in base-4.20.2.0 · Control.Monad.ZipFoldable1 IdentityDefined in base-4.20.2.0 · Data.Foldable1Eq1 IdentityDefined in base-4.20.2.0 · Data.Functor.ClassesOrd1 IdentityDefined in base-4.20.2.0 · Data.Functor.ClassesRead1 IdentityDefined in base-4.20.2.0 · Data.Functor.ClassesShow1 IdentityDefined in base-4.20.2.0 · Data.Functor.ClassesNFData1 IdentityDefined in deepseq-1.5.0.0 · Control.DeepSeqHashable1 IdentityDefined in hashable-1.4.7.0 · Data.Hashable.ClassGeneric1 IdentityDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.IdentityUnbox a => Vector Vector (Identity a)Defined in vector-0.13.2.0 · Data.Vector.Unboxed.BaseUnbox a => MVector MVector (Identity a)Defined in vector-0.13.2.0 · Data.Vector.Unboxed.BaseMonoid w => MonadAccum w (AccumT w Identity)Defined in mtl-2.3.1 · Control.Monad.AccumMonadSelect r (SelectT r Identity)Defined in mtl-2.3.1 · Control.Monad.SelectBounded a => Bounded (Identity a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.IdentityEnum a => Enum (Identity a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.IdentityEq a => Eq (Identity a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.IdentityFloating a => Floating (Identity a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.IdentityFractional a => Fractional (Identity a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.IdentityIntegral a => Integral (Identity a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.IdentityData a => Data (Identity a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.DataNum a => Num (Identity a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.IdentityOrd a => Ord (Identity a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.IdentityRead a => Read (Identity a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.IdentityThis instance would be equivalent to the derived instances of the Identity newtype if the runIdentity field were removed
Real a => Real (Identity a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.IdentityRealFloat a => RealFloat (Identity a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.IdentityRealFrac a => RealFrac (Identity a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.IdentityShow a => Show (Identity a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.IdentityThis instance would be equivalent to the derived instances of the Identity newtype if the runIdentity field were removed
Ix a => Ix (Identity a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.IdentityIsString a => IsString (Identity a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.StringGeneric (Identity a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.IdentitySemigroup a => Semigroup (Identity a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.IdentityMonoid a => Monoid (Identity a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.IdentityBits a => Bits (Identity a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.IdentityFiniteBits a => FiniteBits (Identity a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.IdentityStorable a => Storable (Identity a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.IdentityNFData a => NFData (Identity a)Defined in deepseq-1.5.0.0 · Control.DeepSeqBinary a => Binary (Identity a)Defined in binary-0.8.9.3 · Data.Binary.ClassHashable a => Hashable (Identity a)Defined in hashable-1.4.7.0 · Data.Hashable.ClassPrim a => Prim (Identity a)Defined in primitive-0.9.1.0 · Data.Primitive.TypesUnbox a => Unbox (Identity a)Defined in vector-0.13.2.0 · Data.Vector.Unboxed.BaseMonoFoldable (Identity a)Defined in mono-traversable-1.0.21.0 · Data.MonoTraversableMonoTraversable (Identity a)Defined in mono-traversable-1.0.21.0 · Data.MonoTraversableMonoFunctor (Identity a)Defined in mono-traversable-1.0.21.0 · Data.MonoTraversableMonoPointed (Identity a)Defined in mono-traversable-1.0.21.0 · Data.MonoTraversabletype Rep (Identity a) = D1 ('MetaData "Identity"
"GHC.Internal.Data.Functor.Identity"
"ghc-internal"
'True) (C1 ('MetaCons "Identity"
'PrefixI 'True) (S1 ('MetaSel ('Just "runIdentity"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a)))Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.Identitytype Rep1 Identity = D1 ('MetaData "Identity"
"GHC.Internal.Data.Functor.Identity"
"ghc-internal"
'True) (C1 ('MetaCons "Identity"
'PrefixI 'True) (S1 ('MetaSel ('Just "runIdentity"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) Par1))Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.Identitydata MVector s (Identity a)MV_Identity (MVector s a)data Vector (Identity a)V_Identity (Vector a)type Element (Identity a) = aDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable